Skip to content

Commit

Permalink
Fix double empty folder delete
Browse files Browse the repository at this point in the history
  • Loading branch information
SecretX33 committed Feb 2, 2025
1 parent 1bdac3a commit a67a952
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,6 @@ fn delete_empty_folders(path: &Path, cli: &Cli, counter: &AtomicU32) -> Result<(
if entry_path.is_dir() {
// Recursively delete empty subfolders
delete_empty_folders(&entry_path, cli, counter)?;

// Check if the subfolder is now empty
if entry_path.read_dir()?.next().is_none() {
delete_empty_folder(&entry_path, cli, counter)?;
} else {
is_empty = false;
}
} else {
// If there's a file, the folder is not empty
is_empty = false;
Expand All @@ -255,6 +248,11 @@ fn delete_empty_folders(path: &Path, cli: &Cli, counter: &AtomicU32) -> Result<(
}

fn delete_empty_folder(path: &Path, cli: &Cli, counter: &AtomicU32) -> Result<()> {
if !path.exists() {
log!("Warning: tried to delete a path that does not exist: {}", path.display());
return Ok(());
}

let count = counter.fetch_add(1, Ordering::Relaxed);
if cli.dry_run {
log!("{}. Would delete empty folder: {}", count + 1, path.display());
Expand Down

0 comments on commit a67a952

Please sign in to comment.