gh-140774: Fix clearing the read-only file attribute on Windows - #154852
Open
yhay81 wants to merge 1 commit into
Open
gh-140774: Fix clearing the read-only file attribute on Windows#154852yhay81 wants to merge 1 commit into
yhay81 wants to merge 1 commit into
Conversation
SetFileInformationByHandle() interprets a FILE_BASIC_INFO with FileAttributes == 0 as "leave the attributes unchanged", so clearing the read-only flag of a file with no other attribute set was silently ignored by os.chmod(follow_symlinks=True), os.fchmod() and pathlib.Path.chmod(). Substitute FILE_ATTRIBUTE_NORMAL in that case. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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 #140774.
On Windows,
SetFileInformationByHandle()leaves attributes unchanged whenFILE_BASIC_INFO.FileAttributesis zero. Thus clearing the sole read-only attribute silently failed throughos.chmod(..., follow_symlinks=True),os.fchmod(), andpathlib.Path.chmod(). UseFILE_ATTRIBUTE_NORMALin that case.Regression tests cover both handle-based paths.
test_osandtest_pathlibpass.(AI-assisted; reproduced and verified locally on Windows 11.)