Skip to content

Commit

Permalink
No need for result where option will do.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimono-koans committed Jan 3, 2024
1 parent e2d4dcd commit 8511ac7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
40 changes: 16 additions & 24 deletions src/data/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,33 +250,25 @@ impl<'a> ZfsSnapPathGuard<'a> {
}

pub fn target(&self, proximate_dataset_mount: &Path) -> Option<PathBuf> {
self.relative_path(proximate_dataset_mount)
.ok()
.map(|relative| {
self.inner
.path_buf
.ancestors()
.zip(relative.ancestors())
.skip_while(|(a_path, b_path)| a_path == b_path)
.map(|(a_path, _b_path)| a_path)
.collect()
})
self.relative_path(proximate_dataset_mount).map(|relative| {
self.inner
.path_buf
.ancestors()
.zip(relative.ancestors())
.skip_while(|(a_path, b_path)| a_path == b_path)
.map(|(a_path, _b_path)| a_path)
.collect()
})
}

pub fn relative_path(&'a self, proximate_dataset_mount: &'a Path) -> HttmResult<&'a Path> {
let relative_path = self.inner.relative_path(proximate_dataset_mount)?;
let snapshot_stripped_set = relative_path.strip_prefix(ZFS_SNAPSHOT_DIRECTORY)?;
pub fn relative_path(&'a self, proximate_dataset_mount: &'a Path) -> Option<&'a Path> {
let relative_path = self.inner.relative_path(proximate_dataset_mount).ok()?;
let snapshot_stripped_set = relative_path.strip_prefix(ZFS_SNAPSHOT_DIRECTORY).ok()?;

match snapshot_stripped_set.components().next() {
Some(snapshot_name) => {
let res = snapshot_stripped_set.strip_prefix(snapshot_name)?;
Ok(res)
}
None => {
let msg = format!("Path is not a snap path: {:?}", self.inner.path_buf);
Err(HttmError::new(&msg).into())
}
}
snapshot_stripped_set
.components()
.next()
.and_then(|snapshot_name| snapshot_stripped_set.strip_prefix(snapshot_name).ok())
}

pub fn source(&self) -> Option<String> {
Expand Down
1 change: 0 additions & 1 deletion src/display_map/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ impl<'a> From<&MountsForFiles<'a>> for PrintAsMap {
MountDisplay::RelativePath => {
if let Some(relative_path) = opt_spg.and_then(|spd| {
spd.relative_path(&value.path_buf)
.ok()
.map(|path| path.to_path_buf())
}) {
return Some(Cow::Owned(
Expand Down

0 comments on commit 8511ac7

Please sign in to comment.