Skip to content

gh-140774: Fix clearing the read-only file attribute on Windows - #154852

Open
yhay81 wants to merge 1 commit into
python:mainfrom
yhay81:gh-140774-hchmod-clear-readonly
Open

gh-140774: Fix clearing the read-only file attribute on Windows#154852
yhay81 wants to merge 1 commit into
python:mainfrom
yhay81:gh-140774-hchmod-clear-readonly

Conversation

@yhay81

@yhay81 yhay81 commented Jul 29, 2026

Copy link
Copy Markdown

Fixes #140774.

On Windows, SetFileInformationByHandle() leaves attributes unchanged when FILE_BASIC_INFO.FileAttributes is zero. Thus clearing the sole read-only attribute silently failed through os.chmod(..., follow_symlinks=True), os.fchmod(), and pathlib.Path.chmod(). Use FILE_ATTRIBUTE_NORMAL in that case.

Regression tests cover both handle-based paths. test_os and test_pathlib pass.

(AI-assisted; reproduced and verified locally on Windows 11.)

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Path.chmod() silently fails on Windows when archive bit is cleared and follow_symlinks=True

1 participant