[Python-checkins] r75659 - in python/trunk: Lib/distutils/archive_util.py Lib/distutils/tests/test_archive_util.py Misc/NEWS

tarek.ziade python-checkins at python.org
Sat Oct 24 15:29:44 CEST 2009


Author: tarek.ziade
Date: Sat Oct 24 15:29:44 2009
New Revision: 75659

Log:
#7066 - Fixed distutils.archive_util.make_archive behavior so it restores the cwd

Modified:
   python/trunk/Lib/distutils/archive_util.py
   python/trunk/Lib/distutils/tests/test_archive_util.py
   python/trunk/Misc/NEWS

Modified: python/trunk/Lib/distutils/archive_util.py
==============================================================================
--- python/trunk/Lib/distutils/archive_util.py	(original)
+++ python/trunk/Lib/distutils/archive_util.py	Sat Oct 24 15:29:44 2009
@@ -233,9 +233,11 @@
         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

Modified: python/trunk/Lib/distutils/tests/test_archive_util.py
==============================================================================
--- python/trunk/Lib/distutils/tests/test_archive_util.py	(original)
+++ python/trunk/Lib/distutils/tests/test_archive_util.py	Sat Oct 24 15:29:44 2009
@@ -8,7 +8,8 @@
 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 @@
         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)
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sat Oct 24 15:29:44 2009
@@ -418,6 +418,9 @@
 Library
 -------
 
+- Issue #7066: archive_util.make_archive now restores the cwd if an error is 
+  raised. Initial patch by Ezio Melotti.
+
 - Issue #6218: io.StringIO and io.BytesIO instances are now picklable with
   protocol 2.
 


More information about the Python-checkins mailing list