ZipFile.mkdir(ZipInfo.from_file(...)) CRC AttributeError
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
Adding a directory entry to a zip file on the basis of a ZipInfo object (to pick up metadata) fails because ZipFile evidently expects the object to have a CRC attribute even though it's a directory rather than a file. I can work around this bug by storing the ZipInfo in a variable and giving it a nominal CRC (namely 0), but that shouldn't be necessary. Specifically,
import os
import zipfile
with zipfile.ZipFile("bug.zip", mode = "w") as z:
os.chdir('/')
z.mkdir(zipfile.ZipInfo.from_file('usr'))
fails:
File ".../zipfile-bug.py", line 6, in <module>
z.mkdir(zipfile.ZipInfo.from_file('usr'))
File "/usr/lib/python3.12/zipfile/__init__.py", line 1935, in mkdir
self.fp.write(zinfo.FileHeader(False))
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/zipfile/__init__.py", line 460, in FileHeader
CRC = self.CRC
^^^^^^^^
AttributeError: 'ZipInfo' object has no attribute 'CRC'
Could you please take a look?
Thanks!
CPython versions tested on:
3.11, 3.12, 3.13
Operating systems tested on:
Linux
Linked PRs
- gh-119108
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với Lib/zipfile/init.py, đặc biệt là ZipFile.mkdir và ZipInfo.FileHeader, đồng thời tái hiện ví dụ ZipInfo.from_file('usr') được cung cấp. Kiểm tra các bài kiểm thử của zipfile đối với các mục thư mục và thêm coverage cho lời gọi này; được xem là hoàn tất khi ví dụ chạy xong mà không có AttributeError và các bài kiểm thử liên quan đều đạt.
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
- backend
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- 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