diff --git a/src/path.rs b/src/path.rs index 4b0856c..724d0eb 100644 --- a/src/path.rs +++ b/src/path.rs @@ -362,6 +362,15 @@ impl StrictPath { } } + /// This is for a special case when we're scanning a dummy root. + pub fn interpret_unless_skip(&self) -> Result { + if self.raw == SKIP { + Ok(SKIP.to_string()) + } else { + self.interpret() + } + } + pub fn interpreted(&self) -> Result { Ok(Self { raw: self.interpret()?, diff --git a/src/scan.rs b/src/scan.rs index fac3b72..0174f68 100644 --- a/src/scan.rs +++ b/src/scan.rs @@ -129,7 +129,7 @@ pub fn parse_paths( None => SKIP, }; - let Ok(root_interpreted) = root.path.interpret() else { + let Ok(root_interpreted) = root.path.interpret_unless_skip() else { return HashSet::new(); }; let data_dir = CommonPath::Data.get_or_skip(); @@ -432,12 +432,7 @@ pub fn parse_paths( paths .iter() - .map(|(x, y)| { - ( - StrictPath::relative(x.to_string(), Some(manifest_dir.interpret().unwrap())), - *y, - ) - }) + .map(|(x, y)| (StrictPath::relative(x.to_string(), manifest_dir.interpret().ok()), *y)) .collect() } @@ -464,8 +459,11 @@ pub fn scan_game_for_backup( let mut paths_to_check = HashSet::<(StrictPath, Option)>::new(); // Add a dummy root for checking paths without ``. - let mut roots_to_check: Vec> = vec![None]; - roots_to_check.extend(roots.iter().cloned().map(Some)); + let mut roots_to_check: Vec = vec![RootsConfig { + path: StrictPath::new(SKIP.to_string()), + store: Store::Other, + }]; + roots_to_check.extend(roots.iter().cloned()); let manifest_dir_interpreted = manifest_dir.interpret().unwrap(); let steam_ids = steam_ids(game, steam_shortcuts.get(name)); @@ -492,12 +490,6 @@ pub fn scan_game_for_backup( } for root in roots_to_check { - let dummy = root.is_none(); - let root = root.unwrap_or_else(|| RootsConfig { - path: StrictPath::new(SKIP.to_string()), - store: Store::Other, - }); - log::trace!( "[{name}] adding candidates from {:?} root: {}", root.store, @@ -506,11 +498,7 @@ pub fn scan_game_for_backup( if root.path.raw().trim().is_empty() { continue; } - let Ok(root_interpreted) = (if dummy { - Ok(root.path.raw()) - } else { - root.path.interpret() - }) else { + let Ok(root_interpreted) = root.path.interpret_unless_skip() else { log::error!("Invalid root: {:?}", &root.path); continue; }; @@ -795,15 +783,15 @@ pub fn scan_game_for_backup( } fn scan_game_for_backup_add_prefix( - roots_to_check: &mut Vec>, + roots_to_check: &mut Vec, paths_to_check: &mut HashSet<(StrictPath, Option)>, wp: &StrictPath, has_registry: bool, ) { - roots_to_check.push(Some(RootsConfig { + roots_to_check.push(RootsConfig { path: wp.clone(), store: Store::OtherWine, - })); + }); if has_registry { paths_to_check.insert((wp.joined("*.reg"), None)); }