python / python/cpython

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

オープン
#140,774 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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 state
  • Path.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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、アーカイブビットが設定されている場合と設定されていない場合の、提供された Path.chmod() 用 Windows 再現プログラムを実行し、次に follow_symlinks=True と os.chmod() の動作を比較してください。続行する前に、gh-142018 と gh-154852 にリンクされた作業を確認してください。両方のアーカイブビット状態で読み取り専用属性が一貫してクリアされれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。