Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #539 from cgwalters/cleanup-context
Browse files Browse the repository at this point in the history
commit: Add more context
  • Loading branch information
jmarrero authored Sep 18, 2023
2 parents f1afc04 + dc81fb0 commit 691b14e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ fn process_vardir_recurse(
/// Recursively remove the target directory, but avoid traversing across mount points.
fn remove_all_on_mount_recurse(root: &Dir, rootdev: u64, path: &Path) -> Result<bool> {
let mut skipped = false;
for entry in root.read_dir(path)? {
for entry in root
.read_dir(path)
.with_context(|| format!("Reading {path:?}"))?
{
let entry = entry?;
let metadata = entry.metadata()?;
if metadata.dev() != rootdev {
Expand All @@ -87,11 +90,13 @@ fn remove_all_on_mount_recurse(root: &Dir, rootdev: u64, path: &Path) -> Result<
if metadata.is_dir() {
skipped |= remove_all_on_mount_recurse(root, rootdev, path.as_path())?;
} else {
root.remove_file(path)?;
root.remove_file(path)
.with_context(|| format!("Removing {path:?}"))?;
}
}
if !skipped {
root.remove_dir(path)?;
root.remove_dir(path)
.with_context(|| format!("Removing {path:?}"))?;
}
Ok(skipped)
}
Expand All @@ -109,7 +114,8 @@ fn clean_subdir(root: &Dir, rootdev: u64) -> Result<()> {
if metadata.is_dir() {
remove_all_on_mount_recurse(root, rootdev, &path)?;
} else {
root.remove_file(&path)?;
root.remove_file(&path)
.with_context(|| format!("Removing {path:?}"))?;
}
}
Ok(())
Expand Down

0 comments on commit 691b14e

Please sign in to comment.