Skip to content

Commit

Permalink
Make more explicit special case for dummy root
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Apr 8, 2024
1 parent 0a40772 commit 2fcd201
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
9 changes: 9 additions & 0 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, StrictPathError> {
if self.raw == SKIP {
Ok(SKIP.to_string())
} else {
self.interpret()
}
}

pub fn interpreted(&self) -> Result<Self, StrictPathError> {
Ok(Self {
raw: self.interpret()?,
Expand Down
34 changes: 11 additions & 23 deletions src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
}

Expand All @@ -464,8 +459,11 @@ pub fn scan_game_for_backup(
let mut paths_to_check = HashSet::<(StrictPath, Option<bool>)>::new();

// Add a dummy root for checking paths without `<root>`.
let mut roots_to_check: Vec<Option<RootsConfig>> = vec![None];
roots_to_check.extend(roots.iter().cloned().map(Some));
let mut roots_to_check: Vec<RootsConfig> = 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));
Expand All @@ -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,
Expand All @@ -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;
};
Expand Down Expand Up @@ -795,15 +783,15 @@ pub fn scan_game_for_backup(
}

fn scan_game_for_backup_add_prefix(
roots_to_check: &mut Vec<Option<RootsConfig>>,
roots_to_check: &mut Vec<RootsConfig>,
paths_to_check: &mut HashSet<(StrictPath, Option<bool>)>,
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));
}
Expand Down

0 comments on commit 2fcd201

Please sign in to comment.