]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #21280: Fixed a bug in shutil.make_archive() when create an archive of
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 27 Nov 2014 22:48:46 +0000 (00:48 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 27 Nov 2014 22:48:46 +0000 (00:48 +0200)
current directory in current directory.

Lib/shutil.py
Lib/test/test_shutil.py

index b5e7cbe3d5daa62be82046b8631d5e4e00c6d93d..22958f42046f7d74e4b978f95712285ad3238141 100644 (file)
@@ -600,7 +600,7 @@ def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
     archive_name = base_name + '.tar' + compress_ext.get(compress, '')
     archive_dir = os.path.dirname(archive_name)
 
-    if not os.path.exists(archive_dir):
+    if archive_dir and not os.path.exists(archive_dir):
         if logger is not None:
             logger.info("creating %s", archive_dir)
         if not dry_run:
@@ -660,7 +660,7 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
     zip_filename = base_name + ".zip"
     archive_dir = os.path.dirname(base_name)
 
-    if not os.path.exists(archive_dir):
+    if archive_dir and not os.path.exists(archive_dir):
         if logger is not None:
             logger.info("creating %s", archive_dir)
         if not dry_run:
index c4306da5e4143a6910a87f34c0e89c5fb406334b..349036291b24ca459298fcd77fd50a1b2935074a 100644 (file)
@@ -1126,6 +1126,21 @@ class TestShutil(unittest.TestCase):
         finally:
             unregister_archive_format('xxx')
 
+    def test_make_tarfile_in_curdir(self):
+        # Issue #21280
+        root_dir = self.mkdtemp()
+        with support.change_cwd(root_dir):
+            self.assertEqual(make_archive('test', 'tar'), 'test.tar')
+            self.assertTrue(os.path.isfile('test.tar'))
+
+    @requires_zlib
+    def test_make_zipfile_in_curdir(self):
+        # Issue #21280
+        root_dir = self.mkdtemp()
+        with support.change_cwd(root_dir):
+            self.assertEqual(make_archive('test', 'zip'), 'test.zip')
+            self.assertTrue(os.path.isfile('test.zip'))
+
     def test_register_archive_format(self):
 
         self.assertRaises(TypeError, register_archive_format, 'xxx', 1)