Use copy instead of move when pasting to different device, fixes #337

This commit is contained in:
Jeremy Soller 2024-09-17 12:55:13 -06:00
parent d0359af0b5
commit 136b1e6c37
No known key found for this signature in database
GPG key ID: D02FD439211AF56F

View file

@ -1950,10 +1950,34 @@ impl Application for App {
});
}
ClipboardKind::Cut => {
self.operation(Operation::Move {
paths: contents.paths,
to,
});
//TODO: determine ability to move on non-Unix systems
let mut can_move = true;
#[cfg(unix)]
{
use std::os::unix::fs::MetadataExt;
//TODO: better error handling, fall back to not moving?
if let Ok(to_meta) = fs::metadata(&to) {
for path in contents.paths.iter() {
if let Ok(meta) = fs::metadata(path) {
if meta.dev() != to_meta.dev() {
can_move = false;
}
}
}
}
}
if can_move {
self.operation(Operation::Move {
paths: contents.paths,
to,
});
} else {
self.operation(Operation::Copy {
paths: contents.paths,
to,
});
}
}
}
}