chore: use compio::fs::rename for quick renames
This commit is contained in:
parent
15e40461e5
commit
e21989aaa3
1 changed files with 37 additions and 27 deletions
|
|
@ -114,7 +114,7 @@ async fn copy_or_move(
|
|||
);
|
||||
|
||||
// Handle duplicate file names by renaming paths
|
||||
let mut from_to_pairs: Vec<(PathBuf, PathBuf)> = paths
|
||||
let from_to_pairs_iter = paths
|
||||
.into_iter()
|
||||
.zip(std::iter::repeat(to.as_path()))
|
||||
.filter_map(|(from, to)| {
|
||||
|
|
@ -132,23 +132,23 @@ async fn copy_or_move(
|
|||
//TODO: how to handle from missing file name?
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
});
|
||||
|
||||
// Attempt quick and simple renames
|
||||
//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?
|
||||
if to.exists() {
|
||||
return true;
|
||||
return Some((from, to));
|
||||
}
|
||||
|
||||
//TODO: use compio::fs::rename?
|
||||
match fs::rename(from, to) {
|
||||
match compio::fs::rename(&from, &to).await {
|
||||
Ok(()) => {
|
||||
log::info!("renamed {} to {}", from.display(), to.display());
|
||||
false
|
||||
None
|
||||
}
|
||||
Err(err) => {
|
||||
log::info!(
|
||||
|
|
@ -157,11 +157,21 @@ async fn copy_or_move(
|
|||
to.display(),
|
||||
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());
|
||||
|
||||
|
|
@ -219,7 +229,7 @@ pub async fn sync_to_disk(
|
|||
}
|
||||
}))
|
||||
.buffer_unordered(32)
|
||||
.collect::<Vec<_>>()
|
||||
.collect::<()>()
|
||||
.await;
|
||||
|
||||
// Sync directories to disk
|
||||
|
|
@ -229,7 +239,7 @@ pub async fn sync_to_disk(
|
|||
}
|
||||
}))
|
||||
.buffer_unordered(16)
|
||||
.collect::<Vec<_>>()
|
||||
.collect::<()>()
|
||||
.await;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue