From 527b4fe0e894e0f09044e6ddc8b0fd1a38b15706 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 26 Jan 2008 17:46:49 +0000 Subject: [PATCH] The 'extract' argument didn't work with zip archives. Firstly, we put it in the wrong place, and secondly because unzip uses it as a pattern to filter the results, not as the name of the thing to extract. Reported by Ilja Honkonen. --- zeroinstall/zerostore/unpack.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/zeroinstall/zerostore/unpack.py b/zeroinstall/zerostore/unpack.py index 4a15417..6c467f2 100644 --- a/zeroinstall/zerostore/unpack.py +++ b/zeroinstall/zerostore/unpack.py @@ -282,14 +282,21 @@ def extract_zip(stream, destdir, extract, start_offset = 0): shutil.copyfileobj(stream, zip_copy) zip_copy.close() - args = ['unzip', '-q', '-o'] + args = ['unzip', '-q', '-o', 'archive.zip'] if extract: - args.append(extract) + args.append(extract + '/*') - _extract(stream, destdir, args + ['archive.zip']) + _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: # Limit the characters we accept, to avoid sending dodgy -- 2.11.4.GIT