changeset: 99286:09ed44192995 parent: 99282:de5a11836ad4 parent: 99285:0f8d426e0d0c user: Serhiy Storchaka date: Sun Nov 22 14:50:59 2015 +0200 files: Misc/ACKS Misc/NEWS description: Issue #25624: ZipFile now always writes a ZIP_STORED header for directory entries. Patch by Dingyuan Wang. diff -r de5a11836ad4 -r 09ed44192995 Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py Sun Nov 22 12:30:54 2015 +0200 +++ b/Lib/test/test_shutil.py Sun Nov 22 14:50:59 2015 +0200 @@ -1105,6 +1105,29 @@ 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 -r de5a11836ad4 -r 09ed44192995 Lib/zipfile.py --- a/Lib/zipfile.py Sun Nov 22 12:30:54 2015 +0200 +++ b/Lib/zipfile.py Sun Nov 22 14:50:59 2015 +0200 @@ -1444,7 +1444,9 @@ 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 -r de5a11836ad4 -r 09ed44192995 Misc/ACKS --- a/Misc/ACKS Sun Nov 22 12:30:54 2015 +0200 +++ b/Misc/ACKS Sun Nov 22 14:50:59 2015 +0200 @@ -1522,6 +1522,7 @@ Larry Wall Kevin Walzer Rodrigo Steinmuller Wanderley +Dingyuan Wang Ke Wang Greg Ward Tom Wardill diff -r de5a11836ad4 -r 09ed44192995 Misc/NEWS --- a/Misc/NEWS Sun Nov 22 12:30:54 2015 +0200 +++ b/Misc/NEWS Sun Nov 22 14:50:59 2015 +0200 @@ -95,6 +95,9 @@ 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