From dc81fb0ec99bff886f7bf4cf5943f44a32fb6322 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 16 Sep 2023 17:15:05 -0400 Subject: [PATCH] commit: Add more context I got a bare `error: Cleaning run: Device or resource busy (os error 16)` in a container build, and it'd have been useful to know exactly which path was failing. --- lib/src/commit.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/src/commit.rs b/lib/src/commit.rs index a9252400..e0bc0cc8 100644 --- a/lib/src/commit.rs +++ b/lib/src/commit.rs @@ -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 { 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 { @@ -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) } @@ -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(())