]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #28488: shutil.make_archive() no longer adds entry "./" to ZIP archive.
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 23 Oct 2016 12:55:09 +0000 (15:55 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 23 Oct 2016 12:55:09 +0000 (15:55 +0300)
Lib/shutil.py
Lib/test/test_shutil.py
Misc/NEWS

index dc9f2ebc0051e9a0452ac1824f562de4aa8287bf..6cf88d9fac66e2ace699baf8287e709f5f8f4ebd 100644 (file)
@@ -680,9 +680,10 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
         with zipfile.ZipFile(zip_filename, "w",
                              compression=zipfile.ZIP_DEFLATED) as zf:
             path = os.path.normpath(base_dir)
-            zf.write(path, path)
-            if logger is not None:
-                logger.info("adding '%s'", path)
+            if path != os.curdir:
+                zf.write(path, path)
+                if logger is not None:
+                    logger.info("adding '%s'", path)
             for dirpath, dirnames, filenames in os.walk(base_dir):
                 for name in sorted(dirnames):
                     path = os.path.normpath(os.path.join(dirpath, name))
index 1d5e01a92dae0973e46853b556aeb2ac19471604..1e65a2a471dc6be7107aa2ccf3899eb637ab03bc 100644 (file)
@@ -1066,6 +1066,19 @@ class TestShutil(unittest.TestCase):
         work_dir = os.path.dirname(tmpdir2)
         rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive')
 
+        with support.change_cwd(work_dir):
+            base_name = os.path.abspath(rel_base_name)
+            res = make_archive(rel_base_name, 'zip', root_dir)
+
+        self.assertEqual(res, base_name + '.zip')
+        self.assertTrue(os.path.isfile(res))
+        self.assertTrue(zipfile.is_zipfile(res))
+        with zipfile.ZipFile(res) as zf:
+            self.assertCountEqual(zf.namelist(),
+                    ['dist/', 'dist/sub/', 'dist/sub2/',
+                     'dist/file1', 'dist/file2', 'dist/sub/file3',
+                     'outer'])
+
         with support.change_cwd(work_dir):
             base_name = os.path.abspath(rel_base_name)
             res = make_archive(rel_base_name, 'zip', root_dir, base_dir)
index 8c091a00ef675c3a8576ef9c5d64ba6d33758a5e..33dcb7613ce60f23f0938f6ca1359b5891e1016b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -110,6 +110,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #28488: shutil.make_archive() no longer add entry "./" to ZIP archive.
+
 - Issue #24452: Make webbrowser support Chrome on Mac OS X.
 
 - Issue #20766: Fix references leaked by pdb in the handling of SIGINT