fix: skip empty dir removal on single files and skip if dir is not empty
This commit is contained in:
+2
-2
@@ -52,7 +52,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
let tag = get_metadata(&path);
|
let tag = get_metadata(&path);
|
||||||
if let Err(e) =
|
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);
|
eprintln!("Failed to import {:?}: {}", path, e);
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
} else {
|
} else {
|
||||||
println!("Importing file: {:?}", file);
|
println!("Importing file: {:?}", file);
|
||||||
let tag = get_metadata(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 } => {
|
Commands::Show { file } => {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ pub fn move_files(
|
|||||||
tag: Tag,
|
tag: Tag,
|
||||||
extra_files: [String; 8],
|
extra_files: [String; 8],
|
||||||
should_copy: bool,
|
should_copy: bool,
|
||||||
|
has_parent: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let target_dir = PathBuf::from("/home/user/Desktop/coding/keks-sort");
|
let target_dir = PathBuf::from("/home/user/Desktop/coding/keks-sort");
|
||||||
|
|
||||||
@@ -65,7 +66,12 @@ pub fn move_files(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let is_empty = file_path.parent().unwrap().read_dir()?.next().is_none();
|
||||||
|
if has_parent && is_empty {
|
||||||
remove_dir(file_path.parent().unwrap())?;
|
remove_dir(file_path.parent().unwrap())?;
|
||||||
|
}
|
||||||
|
|
||||||
println!("Imported file: {:?}", file_path.file_name().unwrap());
|
println!("Imported file: {:?}", file_path.file_name().unwrap());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user