summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-23 15:57:42 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-23 15:57:42 +0300
commit7fc92bb38a47f7da044847f8112e17201abf79bd (patch)
treecc6777e41b84afedcd4636c4a6046199a603dc69
parent89ecb4ac1046397ae0fc09676adf90ef7a72ea95 (diff)
parent666de7772708047b63125126b0147931571254a4 (diff)
downloadcpython-git-7fc92bb38a47f7da044847f8112e17201abf79bd.tar.gz
Issue #28488: shutil.make_archive() no longer adds entry "./" to ZIP archive.
-rw-r--r--Lib/shutil.py7
-rw-r--r--Lib/test/test_shutil.py13
-rw-r--r--Misc/NEWS2
3 files changed, 19 insertions, 3 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 9d193b567c..90b71986a9 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -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))
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index 990fae55db..d93efb8867 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -1066,6 +1066,19 @@ class TestShutil(unittest.TestCase):
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)
self.assertEqual(res, base_name + '.zip')
diff --git a/Misc/NEWS b/Misc/NEWS
index 0021b19ac4..3f3b995d0a 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -23,6 +23,8 @@ Core and Builtins
Library
-------
+- Issue #28488: shutil.make_archive() no longer adds entry "./" to ZIP archive.
+
- Issue #25953: re.sub() now raises an error for invalid numerical group
reference in replacement template even if the pattern is not found in
the string. Error message for invalid group reference now includes the