mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
#7066 - Fixed distutils.archive_util.make_archive behavior so it restores the cwd
This commit is contained in:
parent
1d6e2e1833
commit
672422a328
3 changed files with 25 additions and 5 deletions
|
|
@ -233,9 +233,11 @@ def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
|
||||||
kwargs['owner'] = owner
|
kwargs['owner'] = owner
|
||||||
kwargs['group'] = group
|
kwargs['group'] = group
|
||||||
|
|
||||||
filename = func(base_name, base_dir, **kwargs)
|
try:
|
||||||
if root_dir is not None:
|
filename = func(base_name, base_dir, **kwargs)
|
||||||
log.debug("changing back to '%s'", save_cwd)
|
finally:
|
||||||
os.chdir(save_cwd)
|
if root_dir is not None:
|
||||||
|
log.debug("changing back to '%s'", save_cwd)
|
||||||
|
os.chdir(save_cwd)
|
||||||
|
|
||||||
return filename
|
return filename
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ from os.path import splitdrive
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from distutils.archive_util import (check_archive_formats, make_tarball,
|
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.spawn import find_executable, spawn
|
||||||
from distutils.tests import support
|
from distutils.tests import support
|
||||||
from test.test_support import check_warnings
|
from test.test_support import check_warnings
|
||||||
|
|
@ -262,6 +263,20 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
||||||
finally:
|
finally:
|
||||||
archive.close()
|
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():
|
def test_suite():
|
||||||
return unittest.makeSuite(ArchiveUtilTestCase)
|
return unittest.makeSuite(ArchiveUtilTestCase)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -418,6 +418,9 @@ Core and Builtins
|
||||||
Library
|
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
|
- Issue #6218: io.StringIO and io.BytesIO instances are now picklable with
|
||||||
protocol 2.
|
protocol 2.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue