From 136b1e6c379f76d39c0aefcb8e55a2a8d8c7ed2d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 17 Sep 2024 12:55:13 -0600 Subject: [PATCH] Use copy instead of move when pasting to different device, fixes #337 --- src/app.rs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index 24ceed5..a908d61 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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, + }); + } } } }