fix: collect all extra files before renaming to fix failure of renaming
This commit is contained in:
+9
-7
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user