This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Explicit directories for zipfiles
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, alanmcintyre, ethan.furman, sam_ezeh, schmir, schuppenies, serhiy.storchaka, thijs, twouters
Priority: normal Keywords: patch

Created on 2009-01-04 17:09 by schuppenies, last changed 2022-04-11 14:56 by admin.

Files
File name Uploaded Description Edit
test.zip schmir, 2009-09-23 08:34
sam_ezeh.patch sam_ezeh, 2022-03-28 19:24
Pull Requests
URL Status Linked Edit
PR 32160 merged sam_ezeh, 2022-03-28 19:21
Messages (6)
msg79070 - (view) Author: Robert Schuppenies (schuppenies) * (Python committer) Date: 2009-01-04 17:09
We have an issue with the Python cheeseshop which is probably an issue
with Python itself as well.

When we create a zip file with standard linux tools ('zip os-zipped.zip
*'), uploading it works fine. But if we use the zipfile module from
Python and try to upload the result to the cheeseshop, we get this error
message:

" Error unpacking zipfile:[Errno 2] No such file or directory: 
u'/data/packagedocs/Pympler/_sources/index.txt'"

Turns out that the Python-zipped version does not include explicit
directories. The OS-zipped version contains "directory/,
directory/asizeof.txt", the Python-zipped file only
"directory/asizeof.txt". Digging deeper, Python has no way to explicitly
add directories to a zip file.

It would be useful to have an option which allows the explicit creation
of directories inside of zip files. This would help when working with
applications which do not create directories if they are not explicitly
specified.
msg93031 - (view) Author: Ralf Schmitt (schmir) Date: 2009-09-23 08:34
it looks like this is fixed in 2.6.2.

I'm attaching a zipfile which cannot be extracted in 2.6.1

Running
python -c 'import zipfile; zipfile.ZipFile("test.zip").extractall()'
in 2.6.2 however works. 
but you should not do that anyway because of issue 6972
msg176860 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-03 17:47
Actually now creating directories in zipfile is possible with ZipFile.writestr(special_zip_info, b''). However a special method (like ZipFile.mkdir(name)) can be useful.
msg416126 - (view) Author: Sam Ezeh (sam_ezeh) * Date: 2022-03-27 14:00
I'm looking into adding ZipFile.mkdir
msg416203 - (view) Author: Sam Ezeh (sam_ezeh) * Date: 2022-03-28 19:24
I've submitted the above patch. I created the ZipFile.mkdir function, created the necessary tests and wrote the documentation.

I think it is ready for review.
msg416800 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2022-04-05 18:41
New changeset 050a8f94c678a05d506fe192c863c4a572178c42 by Sam Ezeh in branch 'main':
bpo-4833: Add ZipFile.mkdir (GH-32160)
https://github.com/python/cpython/commit/050a8f94c678a05d506fe192c863c4a572178c42
History
Date User Action Args
2022-04-11 14:56:43adminsetgithub: 49083
2022-04-05 18:41:41ethan.furmansetmessages: + msg416800
2022-04-02 21:29:07ethan.furmansetnosy: + twouters, alanmcintyre
2022-03-28 19:59:48ethan.furmansetnosy: + ethan.furman

versions: + Python 3.11, - Python 3.4
2022-03-28 19:24:22sam_ezehsetfiles: + sam_ezeh.patch

messages: + msg416203
2022-03-28 19:21:18sam_ezehsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request30238
2022-03-27 14:00:14sam_ezehsetmessages: + msg416126
2022-03-27 13:42:54sam_ezehsetnosy: + sam_ezeh
2012-12-03 17:47:17serhiy.storchakasetversions: + Python 3.4
nosy: + serhiy.storchaka

messages: + msg176860

stage: needs patch
2011-05-30 21:45:57Arfreversetnosy: + Arfrever
2011-02-01 18:39:45thijssetnosy: + thijs
2009-09-23 08:34:22schmirsetfiles: + test.zip
nosy: + schmir
messages: + msg93031

2009-01-04 17:09:27schuppeniescreate