diff options
author | Benjamin Peterson <benjamin@python.org> | 2015-11-22 19:04:56 -0800 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2015-11-22 19:04:56 -0800 |
commit | 5323ed3424710f640b643cc467bb628825d58a94 (patch) | |
tree | 3fb21f63dbfbcf793b687dedc40ea2703ca7a7aa | |
parent | 85592c9c80d169e336cfeae6de0c3361f7437166 (diff) | |
download | cpython-5323ed3424710f640b643cc467bb628825d58a94.tar.gz cpython-5323ed3424710f640b643cc467bb628825d58a94.zip |
Issue #25624: ZipFile now always writes a ZIP_STORED header for directory entries. Patch by Dingyuan Wang.
-rw-r--r-- | Lib/test/test_shutil.py | 23 | ||||
-rw-r--r-- | Lib/zipfile.py | 4 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
4 files changed, 30 insertions, 1 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index 71317b39a5e..c85f25e1bc0 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -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') diff --git a/Lib/zipfile.py b/Lib/zipfile.py index b77e6c88e46..3ab66cea69d 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -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 diff --git a/Misc/ACKS b/Misc/ACKS index 35619ecb5e7..c1f64814992 100644 --- 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 diff --git a/Misc/NEWS b/Misc/NEWS index 6d53301c763..716d36a75e4 100644 --- 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? ================================================ |