]> granicus.if.org Git - python/commitdiff
Issue #25624: ZipFile now always writes a ZIP_STORED header for directory entries...
authorBenjamin Peterson <benjamin@python.org>
Mon, 23 Nov 2015 03:04:56 +0000 (19:04 -0800)
committerBenjamin Peterson <benjamin@python.org>
Mon, 23 Nov 2015 03:04:56 +0000 (19:04 -0800)
Lib/test/test_shutil.py
Lib/zipfile.py
Misc/ACKS
Misc/NEWS

index 71317b39a5e91f3f547d6bdb1983cc763622fb75..c85f25e1bc0dbfa8596ded6caa6a07f19815605c 100644 (file)
@@ -511,6 +511,29 @@ class TestShutil(unittest.TestCase):
             names2 = zf.namelist()
         self.assertEqual(sorted(names), sorted(names2))
 
+    @unittest.skipUnless(zlib, "Requires zlib")
+    @unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
+    @unittest.skipUnless(find_executable('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
+                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')
index b77e6c88e465db74138edc9f689052ccdae7a438..3ab66cea69d89fb32f8570449581a0c5b4a3bbd2 100644 (file)
@@ -1134,7 +1134,9 @@ class ZipFile(object):
             arcname += '/'
         zinfo = ZipInfo(arcname, date_time)
         zinfo.external_attr = (st[0] & 0xFFFF) << 16L      # 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
index 35619ecb5e73f43b7f3736f8ada8c4f415fac171..c1f6481499203ae43e6e4c048b05138de5a5f6c4 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1443,6 +1443,7 @@ Richard Walker
 Larry Wall
 Kevin Walzer
 Rodrigo Steinmuller Wanderley
+Dingyuan Wang
 Ke Wang
 Greg Ward
 Tom Wardill
index 6d53301c76378ae824e37e860ea74b9dba3976f8..716d36a75e4499a6806bb5877d37179fb194691b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #25624: ZipFile now always writes a ZIP_STORED header for directory
+  entries.  Patch by Dingyuan Wang.
+
 
 What's New in Python 2.7.11 release candidate 1?
 ================================================