]> granicus.if.org Git - python/commitdiff
Issue #25624: ZipFile now always writes a ZIP_STORED header for directory
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 22 Nov 2015 12:49:58 +0000 (14:49 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 22 Nov 2015 12:49:58 +0000 (14:49 +0200)
entries.  Patch by Dingyuan Wang.

Lib/test/test_shutil.py
Lib/zipfile.py
Misc/ACKS
Misc/NEWS

index 673d36b6731aaef5ce85e29f5c65e4efa61d05b8..d2d4d0308f8dd8d4e4aeb65c60c314b94dedc270 100644 (file)
@@ -1099,6 +1099,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')
index bda61343571601a4f13a409d5e5020ed677b150b..11d7cf9cb6f11a58234fa8d2ff9b698cf2e97596 100644 (file)
@@ -1337,7 +1337,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
index ec572a1e9479c08d1b81daa7a20e484b34f7e7ff..4b41efa4e6f03ec2a69a87c2e35adfe02744f7d7 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1471,6 +1471,7 @@ Richard Walker
 Larry Wall
 Kevin Walzer
 Rodrigo Steinmuller Wanderley
+Dingyuan Wang
 Ke Wang
 Greg Ward
 Tom Wardill
index 6a5f53e2062bb2b0dc251c711e4e6d2aa0b5ac42..a13e1987a185530e870e55ddac52b91b62d487ae 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -106,6 +106,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #25624: ZipFile now always writes a ZIP_STORED header for directory
+  entries.  Patch by Dingyuan Wang.
+
 - Issue #25583: Avoid incorrect errors raised by os.makedirs(exist_ok=True)
   when the OS gives priority to errors such as EACCES over EEXIST.