Skip to content

bpo-4833: Add ZipFile.mkdir - #32160

Merged
ethanfurman merged 8 commits into
python:mainfrom
dignissimus:bpo-1590744
Apr 5, 2022
Merged

ethanfurman merged 8 commits into
python:mainfrom
dignissimus:bpo-1590744

Conversation

@dignissimus

@dignissimus dignissimus commented Mar 28, 2022 •

Copy link
Copy Markdown
Contributor

Add ZipFile.mkdir method to create directories inside zip archives.

https://bugs.python.org/issue4833

Comment thread Lib/zipfile.py
else:
zinfo._compresslevel = self.compresslevel

if zinfo.is_dir():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that write can no longer be used to create a directory? I suspect that will break existing code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was marked as resolved, but I do not see an answer to my question.

@merwok merwok Mar 30, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think write still accepts directory zinfo, now it’s handled on line 1775 by calling mkdir instead of directly inline here.
There should be a test for write + directory; if not, then this PR needs to add one!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right -- 1175 does handle that. Thanks!

A fairly quick scan of the tests doesn't reveal one using .write(some_directory/). @dignissimus please confirm such a test already exists, or add one.

@ethanfurman ethanfurman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very thorough PR. Question in-line.

@dholth

dholth commented Mar 28, 2022

Copy link
Copy Markdown
Contributor

interesting, since it is also possible to imply directories (if there is a file in there) but this would allow an empty directory

Comment thread Doc/library/zipfile.rst Resolved
@ethanfurman

Copy link
Copy Markdown
Member

@dignissimus : ping me in a few days if no one has merged this yet -- I want to give other folks the chance to review.

@ethanfurman

Copy link
Copy Markdown
Member

@dignissimus Actually, I forgot: have you either verified or added a test for creating a directory using the existing write() method? (Yes, it should work -- nevertheless, a test is good).

@dignissimus

Copy link
Copy Markdown
Contributor Author

@dignissimus Actually, I forgot: have you either verified or added a test for creating a directory using the existing write() method? (Yes, it should work -- nevertheless, a test is good).

@ethanfurman The tests have been added!

@merwok merwok changed the title bpo-4833: Adds ZipFile.mkdir Apr 1, 2022
@dignissimus

Copy link
Copy Markdown
Contributor Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

6 participants