Fix case-only rename on macOS APFS misclassified as two added events#381
Open
mokashang wants to merge 1 commit into
Open
Fix case-only rename on macOS APFS misclassified as two added events#381mokashang wants to merge 1 commit into
mokashang wants to merge 1 commit into
Conversation
On the default case-insensitive APFS filesystem, renaming a file with only a case change (e.g. 'hello.txt' -> 'Hello.txt') produced two ADDED events instead of the expected DELETED + ADDED pair. The macOS notify backend emits two 'Modify(Name(Any))' events for the rename, one for each path, with no source/destination hint. The fallback in src/lib.rs used 'Path::exists' to decide which event was the new path: since APFS resolves both 'hello.txt' and 'Hello.txt' to the same inode, that check returned true for both events and both ended up classified as ADDED. Replace 'Path::exists' with a 'path_exists_exact_case' helper that reads the parent directory and looks for an entry whose file name matches the event path byte-for-byte. On case-sensitive filesystems the behaviour is unchanged. Adds a darwin-only regression test gated on the FS actually being case-insensitive, plus a small fixture file the test renames. Fixes samuelcolvin#368
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #368.
On the default case-insensitive APFS filesystem on macOS, renaming a file with only a case change — e.g.
hello.txt→Hello.txt— produced twoChange.addedevents instead of the expectedChange.deleted(old) + Change.added(new)pair.The macOS notify backend emits two
Modify(Name(Any))events for the rename, one per path, with no source/destination hint. The fallback insrc/lib.rsresolved this by callingPath::existson the event path: the one that exists is the new path (ADDED), the one that doesn't is the old path (DELETED). On a case-insensitive filesystemexists()returnstruefor bothhello.txtandHello.txt(they resolve to the same inode), so both events were misclassified as ADDED.Repro (matches the issue)
Before:
After:
Approach
Add a small
path_exists_exact_casehelper that reads the parent directory and looks for an entry whoseOsStrfile name matches the event path's file name byte-for-byte, and use it in place ofPath::existsfor theModifyKind::Name(_)branch. On case-sensitive filesystems the behaviour is unchanged (the directory entry's name matches exactly when the file exists, andread_dirfinds nothing when it doesn't). On case-insensitive filesystems the rename's old path no longer matches any directory entry, so it is correctly classified as DELETED.I considered using
std::fs::canonicalize+ filename comparison instead, but that follows symlinks and is happy to return an unexpected path when symlinks are in play;read_dirkeeps the check local to the actual parent directory.Tests
test_rename_case_onlyintests/test_rust_notify.py(darwin-only, with an inner skip when the FS happens to be case-sensitive) that renamescase_rename.txt→CASE_RENAME.txtand asserts the DELETED/ADDED pair, then renames back so other tests are unaffected.tests/test_files/case_rename.txt.test_renamecontinues to pass: it renamesa.txt→a.new, so both the source's exact-case entry disappears and the destination's exact-case entry appears, and both branches still resolve as before.Verified locally on macOS 25.5 (APFS, case-insensitive): the new test fails on
mainand passes with this change.cargo clippy -- -D warnings,cargo fmt --check,ruff check,ruff format --check, andmypyare all clean.