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

index 26dcfde7bcbea703cbd6b32b2162aad8cada94a1..388906fd43a92a65e6364b84207861e2c68839c1 100644 (file)
@@ -450,9 +450,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 c85f25e1bc0dbfa8596ded6caa6a07f19815605c..0869a9e553982968e811a94a9b9e1631e15b4711 100644 (file)
@@ -473,6 +473,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.assertEqual(sorted(zf.namelist()),
+                    ['dist/', 'dist/file1', 'dist/file2',
+                     'dist/sub/', 'dist/sub/file3', 'dist/sub2/',
+                     '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 6cf59a31bc1a09dd8c44d38c7cf236beac7c5f2c..dfe93e3c601a34e61e3b7bb7a2096a46c3a41038 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #28488: shutil.make_archive() no longer adds entry "./" to ZIP archive.
+
 - Issue #28480: Fix error building _sqlite3 module when multithreading is
   disabled.