From df77de6cef2e26d74a9d0f59a165ac948f7c44e8 Mon Sep 17 00:00:00 2001 From: Josh Kerr Date: Thu, 19 Nov 2026 16:52:20 -0600 Subject: [PATCH] fix: allow case-only renames on case-insensitive filesystems Renaming notes.txt to Notes.txt was refused with "Notes.txt already exists here" on macOS. A case-insensitive filesystem finds the file itself when asked for the new name, and rclone's stat answers with the name it was asked for, so the guard against renaming onto another entry could not tell the two apart. For a change of case only, look at the folder's real names instead: a clash is refused as before. The test rclone also runs with RCLONE_LOCAL_NO_CLONE: on macOS (APFS) rclone clones a local-to-local copy, which ignores the bandwidth limit, so the tests that throttle a copy to keep it running saw it end at once. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 +++ src/backend/rc.rs | 18 ++++++++++++++++++ tests/common/mod.rs | 6 +++++- tests/rc_backend.rs | 15 +++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0ce48f..da1f5ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ All notable changes to this project are documented here. The format follows response does not include the newer `runningIds` field. - Offer authorization-token login on rclone versions older than 1.75.0, which cannot cancel an in-app browser login cleanly. +- Rename a file to a change of case only (`notes.txt` to `Notes.txt`) on + case-insensitive filesystems, such as macOS's, where the new name was + reported as already in use. ## [0.1.1] - 2026-11-15 diff --git a/src/backend/rc.rs b/src/backend/rc.rs index 317ab17..dca2fe5 100644 --- a/src/backend/rc.rs +++ b/src/backend/rc.rs @@ -54,6 +54,23 @@ impl RcBackend { RcBackend { rc, list_dir } } + /// Whether renaming `from` to `new_name` in `parent` only changes its case and + /// no other entry there has that exact name. A case-insensitive filesystem + /// (macOS, Windows) finds `from` itself when asked for `B.txt` and answers with + /// the name it was asked for, so only the folder's real names tell the two apart. + async fn case_change_only( + &self, + from: &Location, + parent: &Location, + new_name: &str, + ) -> Result { + if new_name.to_lowercase() != from.name().to_lowercase() { + return Ok(false); + } + let entries = self.list(parent).await?; + Ok(!entries.iter().any(|e| e.name == new_name)) + } + /// Write `names` (one per line, relative to the source folder) for `--files-from-raw`. fn write_list(&self, group: &str, names: &[&str]) -> Result { let io = |e: std::io::Error| BackendError::Other(format!("could not write file list: {e}")); @@ -300,6 +317,7 @@ impl Backend for RcBackend { // new name is a change of case only, which is fine. if let Some(taken) = self.stat(&to).await? && taken.name != from.name() + && !self.case_change_only(from, &parent, new_name).await? { return Err(BackendError::Other(format!( "“{}” already exists here", diff --git a/tests/common/mod.rs b/tests/common/mod.rs index f2407ea..3f083e4 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -40,6 +40,10 @@ pub fn rclone_bin() -> Option { /// Keep test daemons independent of environment-defined remotes and credentials. /// The wrapper execs rclone, preserving its PID and the caller's fake-browser PATH. +/// +/// It also turns off cloning: on macOS (APFS) rclone clones a local-to-local copy, +/// which ends at once whatever the bandwidth limit, and the tests that need a copy +/// still running throttle one. Older rclones ignore the unknown variable. pub fn isolated_rclone(binary: &Path, directory: &Path) -> PathBuf { use std::os::unix::fs::PermissionsExt; let quote = |path: &Path| format!("'{}'", path.to_str().unwrap().replace('\'', "'\\''")); @@ -47,7 +51,7 @@ pub fn isolated_rclone(binary: &Path, directory: &Path) -> PathBuf { std::fs::write( &wrapper, format!( - "#!/bin/sh\nexec /usr/bin/env -i PATH=\"$PATH\" HOME={} XDG_CONFIG_HOME={} XDG_CACHE_HOME={} {} \"$@\"\n", + "#!/bin/sh\nexec /usr/bin/env -i PATH=\"$PATH\" HOME={} XDG_CONFIG_HOME={} XDG_CACHE_HOME={} RCLONE_LOCAL_NO_CLONE=true {} \"$@\"\n", quote(directory), quote(&directory.join("config")), quote(&directory.join("cache")), diff --git a/tests/rc_backend.rs b/tests/rc_backend.rs index 6ae3131..51356fe 100644 --- a/tests/rc_backend.rs +++ b/tests/rc_backend.rs @@ -112,6 +112,21 @@ async fn rename_never_lands_on_another_entry() { assert!(root.join("B.txt").exists()); } +#[tokio::test] +async fn a_change_of_case_never_lands_on_another_entry() { + let Some((f, backend)) = setup() else { return }; + let root = &f.root; + std::fs::write(root.join("b.txt"), "b").unwrap(); + std::fs::write(root.join("B.txt"), "keep me").unwrap(); + // A case-insensitive filesystem (macOS) holds one file by now: nothing to clash. + if std::fs::read_dir(root).unwrap().count() < 2 { + return; + } + let e = backend.rename(&tst("b.txt"), "B.txt", false).await.unwrap_err(); + assert!(e.to_string().contains("already exists"), "{e}"); + assert_eq!(std::fs::read_to_string(root.join("B.txt")).unwrap(), "keep me"); +} + #[tokio::test] async fn about_has_totals() { let Some((_f, backend)) = setup() else { return };