Skip to content

Commit

Permalink
No need to wait to gen relative path, can do so once, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimono-koans committed Jan 4, 2024
1 parent 05f205e commit 41e93ce
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 30 deletions.
8 changes: 5 additions & 3 deletions src/data/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ impl PathData {
self.metadata.unwrap_or_else(|| PHANTOM_PATH_METADATA)
}

pub fn relative_path<'a>(&'a self, proximate_dataset_mount: &Path) -> Option<&'a Path> {
pub fn relative_path<'a>(&'a self, proximate_dataset_mount: &Path) -> HttmResult<&'a Path> {
// path strip, if aliased
// fallback if unable to find an alias or strip a prefix
// (each an indication we should not be trying aliases)
self.path_buf.strip_prefix(proximate_dataset_mount).ok()
self.path_buf
.strip_prefix(proximate_dataset_mount)
.map_err(|err| err.into())
}

pub fn proximate_dataset<'a>(&'a self) -> HttmResult<&'a Path> {
Expand Down Expand Up @@ -258,7 +260,7 @@ impl<'a> ZfsSnapPathGuard<'a> {
}

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

snapshot_stripped_set
Expand Down
11 changes: 1 addition & 10 deletions src/display_map/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ impl<'a> From<&MountsForFiles<'a>> for PrintAsMap {
.map(|source| Cow::Owned(source.to_string_lossy().to_string()))
}
MountDisplay::RelativePath => {
if let Some(relative_path) = prox
.opt_alias
.as_ref()
.and_then(|alias| alias.relative_path)
{
return Some(relative_path.to_string_lossy());
}

if let Some(relative_path) = opt_spg.and_then(|spd| {
spd.relative_path(&value.path_buf)
.map(|path| path.to_path_buf())
Expand All @@ -108,8 +100,7 @@ impl<'a> From<&MountsForFiles<'a>> for PrintAsMap {
));
}

key.relative_path(&value.path_buf)
.map(|path| path.to_string_lossy())
Some(prox.relative_path.to_string_lossy())
}
}
})
Expand Down
1 change: 1 addition & 0 deletions src/exec/roll_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ impl RollForward {
fn snap_path(&self, path: &Path) -> Option<PathBuf> {
PathData::from(path)
.relative_path(&self.proximate_dataset_mount)
.ok()
.map(|relative_path| {
let snap_file_path: PathBuf = [
self.proximate_dataset_mount.as_path(),
Expand Down
2 changes: 1 addition & 1 deletion src/library/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub fn preserve_recursive(src: &Path, dst: &Path) -> HttmResult<()> {

let proximate_dataset_mount = dst_pathdata.proximate_dataset()?;

let Some(relative_path) = dst_pathdata.relative_path(proximate_dataset_mount) else {
let Ok(relative_path) = dst_pathdata.relative_path(proximate_dataset_mount) else {
let msg = format!(
"Could not determine relative path for destination: {:?}",
dst
Expand Down
25 changes: 9 additions & 16 deletions src/lookup/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// that was distributed with this source code.

use crate::config::generate::{Config, LastSnapMode, ListSnapsOfType};
use crate::data::paths::AliasedPath;
use crate::data::paths::{CompareVersionsContainer, PathData};
use crate::library::results::{HttmError, HttmResult};
use crate::GLOBAL_CONFIG;
Expand Down Expand Up @@ -163,8 +162,8 @@ impl VersionsMap {
pub struct ProximateDatasetAndOptAlts<'a> {
pub pathdata: &'a PathData,
pub proximate_dataset: &'a Path,
pub relative_path: &'a Path,
pub opt_alts: Option<&'a Vec<PathBuf>>,
pub opt_alias: Option<AliasedPath<'a>>,
}

impl<'a> ProximateDatasetAndOptAlts<'a> {
Expand All @@ -189,6 +188,11 @@ impl<'a> ProximateDatasetAndOptAlts<'a> {
.map(|alias| alias.proximate_dataset)
.map_or_else(|| pathdata.proximate_dataset(), Ok)?;

let relative_path = opt_alias
.as_ref()
.and_then(|alias| alias.relative_path)
.map_or_else(|| pathdata.relative_path(proximate_dataset), Ok)?;

let opt_alts = GLOBAL_CONFIG
.dataset_collection
.opt_map_of_alts
Expand All @@ -199,8 +203,8 @@ impl<'a> ProximateDatasetAndOptAlts<'a> {
Ok(Self {
pathdata,
proximate_dataset,
relative_path,
opt_alts,
opt_alias,
})
}

Expand All @@ -219,12 +223,7 @@ impl<'a> ProximateDatasetAndOptAlts<'a> {

pub fn into_search_bundles(&'a self) -> impl Iterator<Item = RelativePathAndSnapMounts<'a>> {
self.datasets_of_interest().flat_map(|dataset_of_interest| {
RelativePathAndSnapMounts::new(
self.pathdata,
self.proximate_dataset,
&self.opt_alias,
&dataset_of_interest,
)
RelativePathAndSnapMounts::new(self.pathdata, &self.relative_path, &dataset_of_interest)
})
}
}
Expand All @@ -239,19 +238,13 @@ pub struct RelativePathAndSnapMounts<'a> {
impl<'a> RelativePathAndSnapMounts<'a> {
fn new(
pathdata: &'a PathData,
proximate_dataset: &'a Path,
opt_alias: &Option<AliasedPath<'a>>,
relative_path: &'a Path,
dataset_of_interest: &Path,
) -> Option<Self> {
// building our relative path by removing parent below the snap dir
//
// for native searches the prefix is are the dirs below the most proximate dataset
// for user specified dirs/aliases these are specified by the user
let relative_path = opt_alias
.as_ref()
.and_then(|alias| alias.relative_path)
.map_or_else(|| pathdata.relative_path(proximate_dataset), Some)?;

let snap_mounts = GLOBAL_CONFIG
.dataset_collection
.map_of_snaps
Expand Down

0 comments on commit 41e93ce

Please sign in to comment.