[issue22201] python -mzipfile fails to unzip files with folders created by zip

2014-08-16 Thread Ryan Wilson

Ryan Wilson added the comment:

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.

--
keywords: +patch
nosy: +ryantimwilson
versions:  -Python 3.5
Added file: http://bugs.python.org/file36389/fix_zipfile_empty_dir.patch

___
Python tracker 
<http://bugs.python.org/issue22201>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22230] 'python -mzipfile -c' does not zip empty directories

2014-08-19 Thread Ryan Wilson

New submission from Ryan Wilson:

Running command:

$ mkdir foo; python -mzipfile -c foo.zip foo; python -mzipfile -e foo.zip dest
ls: cannot access dest: No such file or directory

This is because 'foo.zip' is empty since running 'python -mzipfile -c foo.zip 
foo' does not zip empty directories.

Running 'unzip foo.zip' also produces:
Archive:  foo.zip
warning [foo.zip]:  zipfile is empty

The following posted patch fixes this issue.

--
components: Library (Lib)
files: add_empty_dirs_to_zipfile.patch
keywords: patch
messages: 225535
nosy: ryantimwilson
priority: normal
severity: normal
status: open
title: 'python -mzipfile -c' does not zip empty directories
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file36416/add_empty_dirs_to_zipfile.patch

___
Python tracker 
<http://bugs.python.org/issue22230>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com