Attempt atomic renames when moving top-level files and folders, fixes #607
This commit is contained in:
parent
dd5fa29e9a
commit
6fa890e3f3
1 changed files with 19 additions and 1 deletions
|
|
@ -285,7 +285,7 @@ async fn copy_or_move(
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle duplicate file names by renaming paths
|
// Handle duplicate file names by renaming paths
|
||||||
let from_to_pairs: Vec<(PathBuf, PathBuf)> = paths
|
let mut from_to_pairs: Vec<(PathBuf, PathBuf)> = 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)| {
|
||||||
|
|
@ -306,6 +306,24 @@ async fn copy_or_move(
|
||||||
})
|
})
|
||||||
.collect();
|
.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)| {
|
||||||
|
//TODO: use compio::fs::rename?
|
||||||
|
match fs::rename(from, to) {
|
||||||
|
Ok(()) => {
|
||||||
|
log::info!("renamed {from:?} to {to:?}");
|
||||||
|
false
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
log::info!("failed to rename {from:?} to {to:?}, fallback to recursive move: {err}");
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let mut context = Context::new(controller.clone());
|
let mut context = Context::new(controller.clone());
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue