chore: use compio::fs::rename for quick renames

This commit is contained in:
Michael Aaron Murphy 2026-04-10 06:09:51 +02:00
parent 15e40461e5
commit e21989aaa3
No known key found for this signature in database
GPG key ID: B2732D4240C9212C

View file

@ -114,7 +114,7 @@ async fn copy_or_move(
); );
// Handle duplicate file names by renaming paths // Handle duplicate file names by renaming paths
let mut from_to_pairs: Vec<(PathBuf, PathBuf)> = paths let from_to_pairs_iter = paths
.into_iter() .into_iter()
.zip(std::iter::repeat(to.as_path())) .zip(std::iter::repeat(to.as_path()))
.filter_map(|(from, to)| { .filter_map(|(from, to)| {
@ -132,23 +132,23 @@ async fn copy_or_move(
//TODO: how to handle from missing file name? //TODO: how to handle from missing file name?
None None
} }
}) });
.collect();
// Attempt quick and simple renames // Attempt quick and simple renames
//TODO: allow rename to be used for directories in recursive context? //TODO: allow rename to be used for directories in recursive context?
if matches!(method, Method::Move { .. }) {
from_to_pairs.retain(|(from, to)| { let from_to_pairs: Vec<(PathBuf, PathBuf)> = if matches!(method, Method::Move { .. }) {
from_to_pairs_iter
.map(|(from, to)| async move {
//TODO: show replace dialog here? //TODO: show replace dialog here?
if to.exists() { if to.exists() {
return true; return Some((from, to));
} }
//TODO: use compio::fs::rename? match compio::fs::rename(&from, &to).await {
match fs::rename(from, to) {
Ok(()) => { Ok(()) => {
log::info!("renamed {} to {}", from.display(), to.display()); log::info!("renamed {} to {}", from.display(), to.display());
false None
} }
Err(err) => { Err(err) => {
log::info!( log::info!(
@ -157,11 +157,21 @@ async fn copy_or_move(
to.display(), to.display(),
err err
); );
true Some((from, to))
} }
} }
}); })
.collect::<cosmic::iced::futures::stream::FuturesOrdered<_>>()
.fold(Vec::new(), |mut pairs, pair| async move {
if let Some(pair) = pair {
pairs.push(pair);
} }
pairs
})
.await
} else {
from_to_pairs_iter.collect()
};
let mut context = Context::new(controller.clone()); let mut context = Context::new(controller.clone());
@ -219,7 +229,7 @@ pub async fn sync_to_disk(
} }
})) }))
.buffer_unordered(32) .buffer_unordered(32)
.collect::<Vec<_>>() .collect::<()>()
.await; .await;
// Sync directories to disk // Sync directories to disk
@ -229,7 +239,7 @@ pub async fn sync_to_disk(
} }
})) }))
.buffer_unordered(16) .buffer_unordered(16)
.collect::<Vec<_>>() .collect::<()>()
.await; .await;
} }