fix(copy): prevent emptying file when copy destination is empty (#421)
Install.sh / build (macos-latest) (push) Has been cancelled
Install.sh / build (ubuntu-latest) (push) Has been cancelled
CI / build-(macos-latest) (push) Has been cancelled
CI / build-(ubuntu-latest) (push) Has been cancelled
CI / build-(windows-latest) (push) Has been cancelled
codeberg-mirror / mirror (push) Has been cancelled
Deploy docs to GitHub Pages / deploy (push) Has been cancelled
Site / build-site (push) Has been cancelled

An empty copy destination resolved to the source file's own path, so
std::fs::copy truncated the original file to 0 bytes.

- localhost::copy now refuses to copy a file onto itself, returning an
  error instead of truncating it (root cause).
- action_copy treats an empty/whitespace destination as a cancel.

Closes #421
This commit is contained in:
Christian Visintin
2026-06-08 17:12:52 +02:00
parent afe7b05830
commit 904befaea8
2 changed files with 55 additions and 0 deletions
@@ -12,6 +12,15 @@ use super::{FileTransferActivity, LogLevel, SelectedFile, TransferPayload};
impl FileTransferActivity {
/// Copy the currently selected file(s) via the active tab's pane.
pub(crate) fn action_copy(&mut self, input: String) {
// An empty destination would resolve to the source itself and could
// empty the original file (#421); treat it as a cancel.
if input.trim().is_empty() {
self.log(
LogLevel::Warn,
"Copy cancelled: no destination was provided".to_string(),
);
return;
}
match self.get_selected_entries() {
SelectedFile::One(entry) => {
let dest_path = PathBuf::from(input);