fix: collect all extra files before renaming to fix failure of renaming

This commit is contained in:
2026-10-07 19:15:17 +02:00
parent 035e4ecc9b
commit 5e3bc38a11
3 changed files with 42 additions and 35 deletions
+9 -7
View File
@@ -12,7 +12,7 @@ use std::path::PathBuf;
pub fn move_files(
file_path: PathBuf,
tag: Tag,
extra_files: [String; 8],
extra_files: [String; 9],
should_copy: bool,
has_parent: bool,
) -> Result<(), Box<dyn std::error::Error>> {
@@ -60,19 +60,21 @@ pub fn move_files(
}
for ext in &extra_files {
let file = file_path.parent().unwrap().join(format!("*.{}", ext));
let pattern = file_path.parent().unwrap().join(format!("*.{}", ext));
for slice in glob(file.to_str().unwrap())? {
let path = slice?;
let paths: Vec<_> = glob(pattern.to_str().unwrap())?.collect::<Result<_, _>>()?;
for path in paths {
let destination = target.join(path.file_name().unwrap());
let result = if should_copy {
copy(&path, target.join(path.file_name().unwrap())).map(|_| ())
copy(&path, &destination).map(|_| ())
} else {
rename(&path, target.join(path.file_name().unwrap()))
rename(&path, &destination)
};
if let Err(e) = result {
println!("Copy failed: {e}");
println!("Copy failed for {:?}: {e}", path);
}
}
}