ZipFile.mkdir(ZipInfo.from_file(...)) CRC AttributeError
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da Lib/zipfile/init.py, in particolare da ZipFile.mkdir e ZipInfo.FileHeader, e riproduci l'esempio fornito di ZipInfo.from_file('usr'). Controlla i test di zipfile per le voci di directory e aggiungi la copertura per questa chiamata; il lavoro è completato quando l'esempio termina senza AttributeError e i test pertinenti hanno esito positivo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 25/100