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.

Author ryantimwilson
Recipients Antony.Lee, ryantimwilson
Date 2014-08-16.19:36:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1408217792.04.0.680050075271.issue22201@psf.upfronthosting.co.za>
In-reply-to
Content
The reason behind this was that zipfile.py currently handles empty directories in zipfiles incorrectly.

On lines 1774 - 1778 in Lib/zipfile.py:

tgtdir = os.path.dirname(tgt)
if not os.path.exists(tgtdir):
    os.makedirs(tgtdir)
with open(tgt, 'wb') as fp:
    fp.write(zf.read(path))

In the case described above, tgt is 'dest/foo/' because the directory is empty. For non-empty directories, tgt would be a file in the directory i.e. 'dest/foo/a'. In the empty directory case, the directory will be created, but then opened as file (which will throw the error shown above).

When compressing the file with 'python -mzipfile -c', zipfile.py would not add empty directories to the zipfile. Hence, the zip file generated is empty.

This patch fixes both issues. In the decompression case, I utilize the Zipfile.extractall() function instead of extracting each file manually. The extractall() function handles empty directories correctly. For the compression case, I added a check to add an empty directory to the zip file.
History
Date User Action Args
2014-08-16 19:36:32ryantimwilsonsetrecipients: + ryantimwilson, Antony.Lee
2014-08-16 19:36:32ryantimwilsonsetmessageid: <1408217792.04.0.680050075271.issue22201@psf.upfronthosting.co.za>
2014-08-16 19:36:32ryantimwilsonlinkissue22201 messages
2014-08-16 19:36:31ryantimwilsoncreate