Skip to content

Commit

Permalink
feat: Better error reporting on removing non-empty directories
Browse files Browse the repository at this point in the history
  • Loading branch information
VorpalBlade committed Jul 25, 2024
1 parent d5d58df commit 068c9d4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/konfigkoll_core/src/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,17 @@ impl Applicator for InProcessApplicator {
let existing = std::fs::symlink_metadata(&instr.path);
if let Ok(metadata) = existing {
if metadata.is_dir() {
std::fs::remove_dir(&instr.path)?;
match std::fs::remove_dir(&instr.path) {
Ok(_) => (),
Err(err) => match err.raw_os_error() {
Some(libc::ENOTEMPTY) => {
Err(err).context("Failed to remove directory: it is not empty (possibly it contains some ignored files). You will have to investigate and resolve this yourself, since we don't want to delete things we shouldn't.")?;
}
Some(_) | None => {
Err(err).context("Failed to remove directory")?;
}
},
}
} else {
std::fs::remove_file(&instr.path)?;
}
Expand Down

0 comments on commit 068c9d4

Please sign in to comment.