Path.chmod() silently fails on Windows when archive bit is cleared and follow_symlinks=True
未關閉
還沒有人認領這個 Issue。
OS-windows
stdlib
topic-pathlib
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先執行提供的 Windows Path.chmod() 重現程式,分別測試設定和未設定封存位元的情況,然後將 follow_symlinks=True 與 os.chmod() 的行為進行比較。繼續之前,請檢視 gh-142018 和 gh-154852 中連結的工作。對於封存位元的兩種狀態都能一致地清除唯讀屬性,即視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- operating-systems
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100