summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-22 12:50:25 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-22 12:50:25 (GMT)
commit6e3d2ba269bc6495cf373bfd8f1c5b0030e6ce4a (patch)
tree7810423008be86a04cf98133dce1c49f7508e70a
parent36e4f760f69a388b5a6097b2e9113dbd464dac90 (diff)
parent8bc792a602311e426cbd69293627fdc9287a5c7b (diff)
downloadcpython-6e3d2ba269bc6495cf373bfd8f1c5b0030e6ce4a.zip
cpython-6e3d2ba269bc6495cf373bfd8f1c5b0030e6ce4a.tar.gz
cpython-6e3d2ba269bc6495cf373bfd8f1c5b0030e6ce4a.tar.bz2
Issue #25624: ZipFile now always writes a ZIP_STORED header for directory
entries. Patch by Dingyuan Wang.
-rw-r--r--Lib/test/test_shutil.py23
-rw-r--r--Lib/zipfile.py4
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 30 insertions, 1 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index 62036dd..ca1d006 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -1105,6 +1105,29 @@ class TestShutil(unittest.TestCase):
names2 = zf.namelist()
self.assertEqual(sorted(names), sorted(names2))
+ @requires_zlib
+ @unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
+ @unittest.skipUnless(shutil.which('unzip'),
+ 'Need the unzip command to run')
+ def test_unzip_zipfile(self):
+ root_dir, base_dir = self._create_files()
+ base_name = os.path.join(self.mkdtemp(), 'archive')
+ archive = make_archive(base_name, 'zip', root_dir, base_dir)
+
+ # check if ZIP file was created
+ self.assertEqual(archive, base_name + '.zip')
+ self.assertTrue(os.path.isfile(archive))
+
+ # now check the ZIP file using `unzip -t`
+ zip_cmd = ['unzip', '-t', archive]
+ with support.change_cwd(root_dir):
+ try:
+ subprocess.check_output(zip_cmd, stderr=subprocess.STDOUT)
+ except subprocess.CalledProcessError as exc:
+ details = exc.output.decode(errors="replace")
+ msg = "{}\n\n**Unzip Output**\n{}"
+ self.fail(msg.format(exc, details))
+
def test_make_archive(self):
tmpdir = self.mkdtemp()
base_name = os.path.join(tmpdir, 'archive')
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 2bd1007..bee00d0 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -1444,7 +1444,9 @@ class ZipFile:
arcname += '/'
zinfo = ZipInfo(arcname, date_time)
zinfo.external_attr = (st[0] & 0xFFFF) << 16 # Unix attributes
- if compress_type is None:
+ if isdir:
+ zinfo.compress_type = ZIP_STORED
+ elif compress_type is None:
zinfo.compress_type = self.compression
else:
zinfo.compress_type = compress_type
diff --git a/Misc/ACKS b/Misc/ACKS
index 1102ff3..b38bdb5 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1518,6 +1518,7 @@ Richard Walker
Larry Wall
Kevin Walzer
Rodrigo Steinmuller Wanderley
+Dingyuan Wang
Ke Wang
Greg Ward
Tom Wardill
diff --git a/Misc/NEWS b/Misc/NEWS
index 428a4d4..6e573e6 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -77,6 +77,9 @@ Core and Builtins
Library
-------
+- Issue #25624: ZipFile now always writes a ZIP_STORED header for directory
+ entries. Patch by Dingyuan Wang.
+
- Issue #25626: Change three zlib functions to accept sizes that fit in
Py_ssize_t, but internally cap those sizes to UINT_MAX. This resolves a
regression in 3.5 where GzipFile.read() failed to read chunks larger than 2