Path.chmod() silently fails on Windows when archive bit is cleared and follow_symlinks=True
Open
Nobody has claimed this yet.
OS-windows
stdlib
topic-pathlib
type-bug
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
Expected behavior:
Path.chmod(stat.S_IWRITE | stat.S_IREAD)should clear the read-only attribute regardless of archive bit statePath.chmod(stat.S_IWRITE | stat.S_IREAD)should match os.chmod() behavior
Actual behavior:
- When archive bit is cleared,
Path.chmod(stat.S_IWRITE | stat.S_IREAD)silently fails to clear read-only - When archive bit is set, it works correctly
Path.chmod(stat.S_IWRITE | stat.S_IREAD, follow_symlinks=False)always works
import os
import stat
import subprocess
from pathlib import Path
def is_read_only(file: str | os.PathLike) -> bool:
return os.stat(file).st_file_attributes & stat.FILE_ATTRIBUTE_READONLY > 0
test_file = Path('test.txt')
test_file.touch()
subprocess.run(f'attrib -a +r {test_file}', check=True)
print(f'Initial (no archive): Read Only: {is_read_only(test_file)}')
test_file.chmod(stat.S_IWRITE | stat.S_IREAD)
print(f'After chmod(follow_symlinks=True): Read Only: {is_read_only(test_file)}')
test_file.chmod(stat.S_IWRITE | stat.S_IREAD, follow_symlinks=False)
print(f'After chmod(follow_symlinks=False): {is_read_only(test_file)}')
subprocess.run(f'attrib +a +r {test_file}', check=True)
print(f'Initial (archive): Read Only: {is_read_only(test_file)}')
test_file.chmod(stat.S_IWRITE | stat.S_IREAD)
print(f'After chmod(follow_symlinks=True): Read Only: {is_read_only(test_file)}')
test_file.chmod(stat.S_IWRITE | stat.S_IREAD, follow_symlinks=False)
print(f'After chmod(follow_symlinks=False): {is_read_only(test_file)}')
Output
Initial (no archive): Read Only: True
After chmod(follow_symlinks=True): Read Only: True
After chmod(follow_symlinks=False): False
Initial (archive): Read Only: True
After chmod(follow_symlinks=True): Read Only: False
After chmod(follow_symlinks=False): False
CPython versions tested on:
3.14
Operating systems tested on:
Windows
Linked PRs
- gh-142018
- gh-154852
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Windows reproducer for Path.chmod() with and without the archive bit, then compare follow_symlinks=True with os.chmod() behavior. Review the linked work in gh-142018 and gh-154852 before proceeding. Done means clearing the read-only attribute consistently for both archive-bit states.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100