Preserve extensions

Do not rename concurrently.

Fortune for lazy-rebuild's current commit: Curse − 凶
rust-version
Avril 3 years ago
parent 40bfa1d01a
commit 5115e3b032

@ -60,18 +60,30 @@ where I: IntoIterator<Item = T>,
let (tx, rx) = handle::spawn_with_cancel(Default::default(), cancel);
let renamer = tokio::spawn(async move {
use futures::prelude::*;
rx.for_each_concurrent(4, |(path, hash)| async move
// XXX: Renameing concurrently is dangerous
rx.for_each(|(path, hash)| async move
{
match hash {
Ok(hash) => {
let new_name = path.parent().unwrap().join(hash.to_hex_string());
let new_name = {
let name = path.parent().unwrap().join(hash.to_hex_string());
if let Some(ext) = path.extension() {
name.with_extension(ext)
} else {
name
}
};
if let Err(_) = tokio::spawn(async move {
match fs::rename(&path, &new_name).await
{
Ok(_) => println!("[.] {:?} -> {:?}", path, new_name),
Err(err) => println!("[!] {:?}: {}", path, err),
if !new_name.exists() {
match fs::rename(&path, &new_name).await
{
Ok(_) => println!("[.] {:?} -> {:?}", path, new_name),
Err(err) => println!("[!] {:?}: {}", path, err),
}
} else {
eprintln!("[w] file exists {:?}", new_name);
}
}).await {
}).await { //XXX: No need to spawn here at all.
eprintln!("[!] panic: rename");
}
},

Loading…
Cancel
Save