python / python/cpython

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

Đang mở
#140,774 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

OS-windows stdlib topic-pathlib type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách chạy trình tái hiện Windows được cung cấp cho Path.chmod() khi có và không có bit lưu trữ, sau đó so sánh follow_symlinks=True với hành vi của os.chmod(). Xem lại công việc được liên kết trong gh-142018 và gh-154852 trước khi tiếp tục. Công việc được xem là hoàn tất khi thuộc tính chỉ-đọc được xóa nhất quán cho cả hai trạng thái của bit lưu trữ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
operating-systems
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.