Skip to content

Conversation

@pareshjoshij
Copy link
Contributor

@pareshjoshij pareshjoshij commented Nov 27, 2025

Fixes #140774.

On Windows, Path.chmod(mode, follow_symlinks=True) fails silently (does not change permissions) if the target file has its Archive bit cleared. This issue arises because passing a Path object directly to os.chmod triggers a behavior difference in the Windows implementation compared to passing a raw string.

The Fix:
Updated Lib/pathlib/__init__.py to explicitly cast the path to a string (str(self)) before passing it to os.chmod.

Verification:
Added a regression test test_chmod_archive_bit_behavior to WindowsPathTest in Lib/test/test_pathlib/test_pathlib.py. The test:

  1. Creates a temporary file.
  2. Manually clears the Archive bit using the Windows attrib command.
  3. Verifies that chmod successfully removes the Read-Only attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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