From: Serhiy Storchaka Date: Thu, 27 Nov 2014 22:50:06 +0000 (+0200) Subject: Issue #21280: Fixed a bug in shutil.make_archive() when create an archive of X-Git-Tag: v2.7.10rc1~308 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c354285f2b29e72547a7e31016024d3f77769b1d;p=python Issue #21280: Fixed a bug in shutil.make_archive() when create an archive of current directory in current directory. --- diff --git a/Lib/shutil.py b/Lib/shutil.py index e12f791fd1..e78a5758ca 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -362,7 +362,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: @@ -426,7 +426,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: diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index 0e811459fc..bcabe75ad7 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -581,6 +581,29 @@ class TestShutil(unittest.TestCase): finally: unregister_archive_format('xxx') + def test_make_tarfile_in_curdir(self): + # Issue #21280 + root_dir = self.mkdtemp() + saved_dir = os.getcwd() + try: + os.chdir(root_dir) + self.assertEqual(make_archive('test', 'tar'), 'test.tar') + self.assertTrue(os.path.isfile('test.tar')) + finally: + os.chdir(saved_dir) + + @unittest.skipUnless(zlib, "Requires zlib") + def test_make_zipfile_in_curdir(self): + # Issue #21280 + root_dir = self.mkdtemp() + saved_dir = os.getcwd() + try: + os.chdir(root_dir) + self.assertEqual(make_archive('test', 'zip'), 'test.zip') + self.assertTrue(os.path.isfile('test.zip')) + finally: + os.chdir(saved_dir) + def test_register_archive_format(self): self.assertRaises(TypeError, register_archive_format, 'xxx', 1)