This commit is contained in:
sxyazi 2024-04-25 18:26:26 +08:00
parent 029375c77f
commit 371ea501fd
No known key found for this signature in database

View file

@ -86,26 +86,21 @@ impl Manager {
for (o, n) in todo { for (o, n) in todo {
let (old, new) = (root.join(&o), root.join(&n)); let (old, new) = (root.join(&o), root.join(&n));
let new_url: Url = new.into(); if accessible(&new).await {
if accessible(&new_url).await {
failed.push((o, n, anyhow!("Destination already exists"))); failed.push((o, n, anyhow!("Destination already exists")));
} else if let Err(e) = fs::rename(&old, &new_url).await { } else if let Err(e) = fs::rename(&old, &new).await {
failed.push((o, n, e.into())); failed.push((o, n, e.into()));
} else if let Ok(f) = File::from(new_url).await { } else if let Ok(f) = File::from(new.into()).await {
let old_url = Url::from(old); succeeded.insert(Url::from(old), f.clone());
succeeded.insert(old_url.clone(), f.clone());
} else { } else {
failed.push((o, n, anyhow!("Failed to retrieve file info"))); failed.push((o, n, anyhow!("Failed to retrieve file info")));
} }
} }
if !succeeded.is_empty() { if !succeeded.is_empty() {
let changes: HashMap<_, _> = // Pubsub::pub_from_bulk(tab, &changes);
succeeded.clone().into_iter().map(|(old, new)| (old, new.url)).collect();
FilesOp::Upserting(cwd, succeeded).emit(); FilesOp::Upserting(cwd, succeeded).emit();
Pubsub::pub_from_bulk(tab, &changes);
} }
drop(permit); drop(permit);