python / python/cpython

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

Offen
#140,774 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

OS-windows stdlib topic-pathlib type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
36k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Führen Sie zunächst den bereitgestellten Windows-Reproducer für Path.chmod() mit und ohne gesetztes Archivbit aus und vergleichen Sie anschließend follow_symlinks=True mit dem Verhalten von os.chmod(). Prüfen Sie die verlinkte Arbeit in gh-142018 und gh-154852, bevor Sie fortfahren. Als erledigt gilt die konsistente Entfernung des Schreibschutzattributs für beide Zustände des Archivbits.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
operating-systems
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.