This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: archive_util.make_archive doesn't restore the cwd if an error is raised
Type: behavior Stage: resolved
Components: Distutils Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: tarek Nosy List: barry, eric.araujo, ezio.melotti, r.david.murray, tarek
Priority: normal Keywords:

Created on 2009-10-05 19:40 by ezio.melotti, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg93618 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-10-05 19:40
archive_util.make_archive() changes the value of the cwd, but if an
error is raised in "filename = func(base_name, base_dir, **kwargs)", the
cwd is not restored. This may happen if zlib is not available and causes
other ~60 tests to fail while running regrtest.py.

This trivial fix solve the problem here:

-    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)

The new test_make_archive_owner_group() test added in r75192 also needs
a @unittest.skipUnless(zlib, "Requires zlib"), otherwise dist_distutils
fails.
Since half of this test doesn't require zlib (i.e. when 'tar' is used)
it might be a good idea to split the test in two, in order to test the
'tar' archives even if 'zlib' is not available.

(Thanks to R. David Murray - he spot the right place where the cwd is
changed and not restored.)
msg93622 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2009-10-05 21:25
I see two distinct points (besides test_make_archive_owner_group):

1- having a try..finally when changing the current working dir (I'll do
this thanks for the patch)

2- dealing with calls made on archive_util.make_archive() when zlib is
not available. What error do you get ? CompressionError I guess ?
msg93624 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-10-05 21:27
======================================================================
ERROR: test_make_archive_owner_group
(distutils.tests.test_archive_util.ArchiveUtilTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/wolf/dev/trunk/Lib/distutils/tests/test_archive_util.py",
line 224, in test_make_archive_owner_group
    group=group)
  File "/home/wolf/dev/trunk/Lib/distutils/archive_util.py", line 237,
in make_archive
    filename = func(base_name, base_dir, **kwargs)
  File "/home/wolf/dev/trunk/Lib/distutils/archive_util.py", line 163,
in make_zipfile
    compression=zipfile.ZIP_DEFLATED)
  File "/home/wolf/dev/trunk/Lib/zipfile.py", line 675, in __init__
    "Compression requires the (missing) zlib module"
RuntimeError: Compression requires the (missing) zlib module
msg94415 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2009-10-24 13:45
Done in r75659, r75662 and r75663 (merge in 2.6 maint. waiting for 2.6.4
final tag to be done)

Thanks !
msg112234 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-01 00:20
Looks like this hasn’t been merged to 2.6 yet.
msg112254 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-01 01:56
Done in r83379.  Note that only the try/except was backported; owner and group don't exist in the 2.6 make_archive signature, nor does the test file exist in 2.6.
History
Date User Action Args
2022-04-11 14:56:53adminsetgithub: 51315
2010-08-01 01:56:07r.david.murraysetstatus: pending -> closed
resolution: accepted -> fixed
messages: + msg112254

stage: resolved
2010-08-01 00:20:19eric.araujosetstatus: closed -> pending
versions: - Python 3.1, Python 2.7, Python 3.2
nosy: + barry, eric.araujo

messages: + msg112234
2009-10-24 13:45:32tareksetstatus: open -> closed

messages: + msg94415
versions: + Python 2.6, Python 3.1
2009-10-05 21:27:15ezio.melottisetmessages: + msg93624
2009-10-05 21:25:15tareksetmessages: + msg93622
2009-10-05 20:48:56tareksetresolution: accepted
2009-10-05 19:40:26ezio.melotticreate