Path.chmod() silently fails on Windows when archive bit is cleared and follow_symlinks=True
Ouverte
Personne n'a encore pris cette issue.
OS-windows
stdlib
topic-pathlib
type-bug
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par exécuter le reproducteur Windows fourni pour Path.chmod() avec et sans le bit d’archive, puis comparez follow_symlinks=True au comportement de os.chmod(). Examinez le travail associé dans gh-142018 et gh-154852 avant de poursuivre. Le travail est considéré comme terminé lorsque l’attribut en lecture seule est supprimé de manière cohérente dans les deux états du bit d’archive.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- operating-systems
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 25/100