[Python-checkins] cpython (2.7): Issue #28488: shutil.make_archive() no longer adds entry "./" to ZIP archive.

serhiy.storchaka python-checkins at python.org
Sun Oct 23 08:58:54 EDT 2016


https://hg.python.org/cpython/rev/847537b7924c
changeset:   104660:847537b7924c
branch:      2.7
parent:      104652:042c923c5b67
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Oct 23 15:52:01 2016 +0300
summary:
  Issue #28488: shutil.make_archive() no longer adds entry "./" to ZIP archive.

files:
  Lib/shutil.py           |   7 ++++---
  Lib/test/test_shutil.py |  13 +++++++++++++
  Misc/NEWS               |   2 ++
  3 files changed, 19 insertions(+), 3 deletions(-)


diff --git a/Lib/shutil.py b/Lib/shutil.py
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -450,9 +450,10 @@
             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))
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -475,6 +475,19 @@
 
         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)
 
         self.assertEqual(res, base_name + '.zip')
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,8 @@
 Library
 -------
 
+- Issue #28488: shutil.make_archive() no longer adds entry "./" to ZIP archive.
+
 - Issue #28480: Fix error building _sqlite3 module when multithreading is
   disabled.
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list