Skip to content

bpo-4833: Add ZipFile.mkdir #32160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 5, 2022
Merged

Conversation

dignissimus
Copy link
Contributor

@dignissimus dignissimus commented Mar 28, 2022

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

https://bugs.python.org/issue4833

@@ -1783,23 +1784,6 @@ def write(self, filename, arcname=None,
else:
zinfo._compresslevel = self.compresslevel

if zinfo.is_dir():
Copy link
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
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.

Copy link
Member

@merwok merwok Mar 30, 2022

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
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.

Copy link
Member

@ethanfurman ethanfurman left a comment

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
Copy link
Contributor

dholth commented Mar 28, 2022

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

@ethanfurman
Copy link
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
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
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 bpo-4833: Add ZipFile.mkdir Apr 1, 2022
@dignissimus
Copy link
Contributor Author

@ethanfurman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants