GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-140774: Fix clearing the read-only file attribute on Windows by yhay81 · Pull Request #154852 · python/cpython

Conversation

@yhay81

@yhay81 yhay81 commented Jul 29, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

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.)

  • Issue: Path.chmod() silently fails on Windows when archive bit is cleared and follow_symlinks=True #140774

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@yhay81
pythongh-140774: Fix clearing the read-only file attribute on Windows
c5f2eb0
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 <[email protected]>
@bedevere-app bedevere-app Bot added the awaiting review label Jul 29, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Jul 29, 2026
Path.chmod() silently fails on Windows when archive bit is cleared and follow_symlinks=True #140774
Open
@github-actions

github-actions Bot commented Oct 29, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Oct 29, 2026
yhay81 added 2 commits November 12, 2026 09:25
@yhay81
Merge remote-tracking branch 'upstream/main' into pythongh-140774-hch…
3b50d3d
…mod-clear-readonly
@yhay81
pythongh-140774: Set SetFileAttributesW argtypes and cover fd/Path.chmod
80c74d0
@yhay81

yhay81 commented Nov 12, 2026

Copy link
Copy Markdown
Author

Merged latest main to refresh CI and expanded Win32ChmodTests to explicitly type SetFileAttributesW and cover os.chmod(fd, ...) and Path.chmod() as well.

cc @serhiy-storchaka @zooba (as author/reviewer of win32_hchmod() in GH-113049 / GH-113192) whenever you have a chance to take a look — check_chmod in test_posix didn't hit this because newly created NTFS files have FILE_ATTRIBUTE_ARCHIVE set, so info.FileAttributes only becomes 0 (which SetFileInformationByHandle / FILE_BASIC_INFO treats as "leave unchanged") when READONLY was the sole attribute.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka approved these changes Nov 12, 2026
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your report and fix. The tests look excessive for such simple fix, but I do not see a way to make them simpler.

LGTM. 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_os/test_windows.py Outdated
finally:
os.close(fd)

def test_pathlib_chmod_clears_readonly_without_other_attributes(self):

@serhiy-storchaka serhiy-storchaka Nov 12, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is redundant. Path.chmod() uses os.chmod().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@yhay81 yhay81 Nov 12, 2026

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point — removed in 362a02a. Thank you for the review!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Nov 12, 2026
@serhiy-storchaka serhiy-storchaka added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes and removed stale Stale PR or inactive for long period of time. labels Nov 12, 2026
@yhay81
pythongh-140774: Remove redundant Path.chmod() test from Win32ChmodTests
362a02a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting merge needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes

Projects

None yet

Milestone

No milestone

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

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@yhay81 @serhiy-storchaka
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.