From 37457c54bd0bdac9f9ca2f0b1f9a617fa803fb83 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 7 Feb 2010 15:27:22 +0000 Subject: [PATCH] Fixed unpacking of zip archives with "extract" unpack.extract_zip() moved the extracted contents up to the parent directory, while all other other extract methods leave them in place. --- tests/testunpack.py | 4 ++++ zeroinstall/zerostore/unpack.py | 10 ++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/testunpack.py b/tests/testunpack.py index b815a18..6a8957b 100755 --- a/tests/testunpack.py +++ b/tests/testunpack.py @@ -41,6 +41,10 @@ class AbstractTestUnpack(BaseTest): unpack.unpack_archive('ftp://foo/file.tgz', file('HelloWorld.tgz'), self.tmpdir, extract = 'HelloWorld') self.assert_manifest('sha1=3ce644dc725f1d21cfcf02562c76f375944b266a') + def testExtractZip(self): + unpack.unpack_archive('ftp://foo/file.zip', file('HelloWorld.zip'), self.tmpdir, extract = 'HelloWorld') + self.assert_manifest('sha1=3ce644dc725f1d21cfcf02562c76f375944b266a') + def testExtractIllegal(self): try: unpack.unpack_archive('ftp://foo/file.tgz', file('HelloWorld.tgz'), self.tmpdir, extract = 'Hello`World`') diff --git a/zeroinstall/zerostore/unpack.py b/zeroinstall/zerostore/unpack.py index 642c376..cd33de9 100644 --- a/zeroinstall/zerostore/unpack.py +++ b/zeroinstall/zerostore/unpack.py @@ -181,7 +181,8 @@ def unpack_archive_over(url, data, destdir, extract = None, type = None, start_o def unpack_archive(url, data, destdir, extract = None, type = None, start_offset = 0): """Unpack stream 'data' into directory 'destdir'. If extract is given, extract just - that sub-directory from the archive. Works out the format from the name.""" + that sub-directory from the archive (i.e. destdir/extract will exist afterwards). + Works out the format from the name.""" if type is None: type = type_from_url(url) if type is None: raise SafeException(_("Unknown extension (and no MIME type given) in '%s'") % url) if type == 'application/x-bzip-compressed-tar': @@ -315,13 +316,6 @@ def extract_zip(stream, destdir, extract, start_offset = 0): _extract(stream, destdir, args) os.unlink(zip_copy_name) - - if extract: - # unzip uses extract just as a filter, so we still need to move things - extracted_dir = os.path.join(destdir, extract) - for x in os.listdir(extracted_dir): - os.rename(os.path.join(extracted_dir, x), os.path.join(destdir, x)) - os.rmdir(extracted_dir) def extract_tar(stream, destdir, extract, decompress, start_offset = 0): if extract: -- 2.11.4.GIT