fix(windows): canonicalize FileTime paths to prevent false overwrite rejections#20071
Open
lars-hagen wants to merge 2 commits intoanomalyco:devfrom
Open
fix(windows): canonicalize FileTime paths to prevent false overwrite rejections#20071lars-hagen wants to merge 2 commits intoanomalyco:devfrom
lars-hagen wants to merge 2 commits intoanomalyco:devfrom
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
1ed499b to
060b779
Compare
…ath-canonicalization
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.
Issue for this PR
Closes #18028
Type of change
What does this PR do?
On Windows the read tool normalizes file paths via
Filesystem.normalizePath(#16069), but
FileTimestores and looks up paths using raw strings. When asymlink, path-casing variant, or relative/absolute mismatch is involved, the
read stores one key and the edit/write assert looks up a different one,
producing a false "You must read file before overwriting it" error.
This covers all the scenarios reported in #18028:
./tmp/file.txtvsc:/Users/.../tmp/file.txt)c:vsC:)This patch adds
Filesystem.normalizePathat the entry of everyFileTimemethod (
read,get,assert,getLock,withLock) so all callers share thesame canonical key. On non-Windows platforms
normalizePathis a no-op, sothere is no behavioral change outside Windows.
Centralizing normalization in
FileTimerather than patching each toolindividually means future tools cannot forget to normalize.
How to reproduce
On Windows, set up a symlinked directory with a file:
Then in OpenCode, read and edit the file through the symlink:
C:\link\test.txtC:\link\test.txtThe read tool normalizes the path to
C:\actual\test.txtand stores it underthat key. The edit tool passes the original
C:\link\test.txttoFileTime.assert, which does not find it. Result:This also reproduces with different drive-letter casing (
c:vsC:) orforward vs backslash variants of the same path.
How did you verify your code works?
bun test test/file/time.test.ts(16 pass)bun test test/tool/edit.test.ts test/tool/write.test.ts(40 pass)FileTime.readwith onepath variant and
FileTime.assertwith another; confirms they resolve tothe same entry.
edit tool across a Windows symlink boundary. The edit succeeds with this
patch and fails without it.
Screenshots / recordings
Checklist