[Windows] Atomic write: clear READONLY on destination and retry rename#2007
Open
clintonpi wants to merge 1 commit into
Open
[Windows] Atomic write: clear READONLY on destination and retry rename#2007clintonpi wants to merge 1 commit into
clintonpi wants to merge 1 commit into
Conversation
Motivation: `SetFileInformationByHandle` with `FileRenameInfoEx` and `FILE_RENAME_FLAG_POSIX_SEMANTICS | FILE_RENAME_FLAG_REPLACE_IF_EXISTS` can fail with `ERROR_ACCESS_DENIED` (mapped from NTSTATUS `STATUS_CANNOT_DELETE`) when the destination has `FILE_ATTRIBUTE_READONLY`. POSIX `rename(2)` is not affected if the destination file itself is read-only. This is the final piece for swiftlang#1485. _Fixes #1507_ Modifications: - When the rename fails with `ERROR_ACCESS_DENIED` and the destination has `FILE_ATTRIBUTE_READONLY` set, clear that attribute and retry the rename once before falling through to the existing `MoveFileExW` fallback. Result: Atomic writes on Windows now replace a read-only destination, aligning with POSIX semantics. Testing: Added a cross-platform test to verify the modification and its consistency.
Author
|
@swift-ci please test |
jmschonfeld
approved these changes
May 29, 2026
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.
Motivation:
SetFileInformationByHandlewithFileRenameInfoExandFILE_RENAME_FLAG_POSIX_SEMANTICS | FILE_RENAME_FLAG_REPLACE_IF_EXISTScan fail withERROR_ACCESS_DENIED(mapped from NTSTATUSSTATUS_CANNOT_DELETE) when the destination hasFILE_ATTRIBUTE_READONLY. POSIXrename(2)is not affected if the destination file itself is read-only. This is the final piece for #1485.Fixes #1507
Modifications:
ERROR_ACCESS_DENIEDand the destination hasFILE_ATTRIBUTE_READONLYset, clear that attribute and retry the rename once before falling through to the existingMoveFileExWfallback.Result:
Atomic writes on Windows now replace a read-only destination, aligning with POSIX semantics.
Testing:
Added a cross-platform test to verify the modification and its consistency.