From f8a51ccd48087ea6f3f6f71bccf8af424bed9c23 Mon Sep 17 00:00:00 2001 From: KeksNino Date: Tue, 1 Sep 2026 20:48:40 +0200 Subject: [PATCH] fix: skip empty dir removal on single files and skip if dir is not empty --- src/main.rs | 4 ++-- src/move_files.rs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index be33398..0e4d54c 100755 --- a/src/main.rs +++ b/src/main.rs @@ -52,7 +52,7 @@ fn main() -> Result<(), Box> { } let tag = get_metadata(&path); if let Err(e) = - move_files(path.clone(), tag.clone(), extra_files.clone(), *copy) + move_files(path.clone(), tag.clone(), extra_files.clone(), *copy, true) { eprintln!("Failed to import {:?}: {}", path, e); } @@ -60,7 +60,7 @@ fn main() -> Result<(), Box> { } else { println!("Importing file: {:?}", file); let tag = get_metadata(file); - move_files(file.clone(), tag.clone(), extra_files, *copy)?; + move_files(file.clone(), tag.clone(), extra_files, *copy, false)?; } } Commands::Show { file } => { diff --git a/src/move_files.rs b/src/move_files.rs index 1fcaaf6..afa82ab 100644 --- a/src/move_files.rs +++ b/src/move_files.rs @@ -10,6 +10,7 @@ pub fn move_files( tag: Tag, extra_files: [String; 8], should_copy: bool, + has_parent: bool, ) -> Result<(), Box> { let target_dir = PathBuf::from("/home/user/Desktop/coding/keks-sort"); @@ -65,7 +66,12 @@ pub fn move_files( } } } - remove_dir(file_path.parent().unwrap())?; + + let is_empty = file_path.parent().unwrap().read_dir()?.next().is_none(); + if has_parent && is_empty { + remove_dir(file_path.parent().unwrap())?; + } + println!("Imported file: {:?}", file_path.file_name().unwrap()); Ok(()) }