summaryrefslogtreecommitdiffstats
path: root/Lib/distutils
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2009-10-24 13:29:44 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2009-10-24 13:29:44 (GMT)
commit672422a328d0a4c9ce5528a64bdefd9a10474caf (patch)
tree8ea4f94c6d1d70e31f95722255812ced69796f8b /Lib/distutils
parent1d6e2e1833864238b903325b37d05fef9b794393 (diff)
downloadcpython-672422a328d0a4c9ce5528a64bdefd9a10474caf.zip
cpython-672422a328d0a4c9ce5528a64bdefd9a10474caf.tar.gz
cpython-672422a328d0a4c9ce5528a64bdefd9a10474caf.tar.bz2
#7066 - Fixed distutils.archive_util.make_archive behavior so it restores the cwd
Diffstat (limited to 'Lib/distutils')
-rw-r--r--Lib/distutils/archive_util.py10
-rw-r--r--Lib/distutils/tests/test_archive_util.py17
2 files changed, 22 insertions, 5 deletions
diff --git a/Lib/distutils/archive_util.py b/Lib/distutils/archive_util.py
index bc5edfd..c741cc0 100644
--- a/Lib/distutils/archive_util.py
+++ b/Lib/distutils/archive_util.py
@@ -233,9 +233,11 @@ def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
kwargs['owner'] = owner
kwargs['group'] = group
- filename = func(base_name, base_dir, **kwargs)
- if root_dir is not None:
- log.debug("changing back to '%s'", save_cwd)
- os.chdir(save_cwd)
+ try:
+ filename = func(base_name, base_dir, **kwargs)
+ finally:
+ if root_dir is not None:
+ log.debug("changing back to '%s'", save_cwd)
+ os.chdir(save_cwd)
return filename
diff --git a/Lib/distutils/tests/test_archive_util.py b/Lib/distutils/tests/test_archive_util.py
index b91986b..a9b46d8 100644
--- a/Lib/distutils/tests/test_archive_util.py
+++ b/Lib/distutils/tests/test_archive_util.py
@@ -8,7 +8,8 @@ from os.path import splitdrive
import warnings
from distutils.archive_util import (check_archive_formats, make_tarball,
- make_zipfile, make_archive)
+ make_zipfile, make_archive,
+ ARCHIVE_FORMATS)
from distutils.spawn import find_executable, spawn
from distutils.tests import support
from test.test_support import check_warnings
@@ -262,6 +263,20 @@ class ArchiveUtilTestCase(support.TempdirManager,
finally:
archive.close()
+ def test_make_archive_cwd(self):
+ current_dir = os.getcwd()
+ def _breaks(*args, **kw):
+ raise RuntimeError()
+ ARCHIVE_FORMATS['xxx'] = (_breaks, [], 'xxx file')
+ try:
+ try:
+ make_archive('xxx', 'xxx', root_dir=self.mkdtemp())
+ except:
+ pass
+ self.assertEquals(os.getcwd(), current_dir)
+ finally:
+ del ARCHIVE_FORMATS['xxx']
+
def test_suite():
return unittest.makeSuite(ArchiveUtilTestCase)