Merge "Use python based unzip function for portability"
This commit is contained in:
@@ -2124,20 +2124,19 @@ def UnzipToDir(filename, dirname, patterns=None):
|
|||||||
archvie. Non-matching patterns will be filtered out. If there's no match
|
archvie. Non-matching patterns will be filtered out. If there's no match
|
||||||
after the filtering, no file will be unzipped.
|
after the filtering, no file will be unzipped.
|
||||||
"""
|
"""
|
||||||
cmd = ["unzip", "-o", "-q", filename, "-d", dirname]
|
with zipfile.ZipFile(filename, allowZip64=True, mode="r") as input_zip:
|
||||||
if patterns is not None:
|
|
||||||
# Filter out non-matching patterns. unzip will complain otherwise.
|
# Filter out non-matching patterns. unzip will complain otherwise.
|
||||||
with zipfile.ZipFile(filename, allowZip64=True) as input_zip:
|
if patterns is not None:
|
||||||
names = input_zip.namelist()
|
names = input_zip.namelist()
|
||||||
filtered = [
|
filtered = [name for name in names if any(
|
||||||
pattern for pattern in patterns if fnmatch.filter(names, pattern)]
|
[fnmatch.fnmatch(name, p) for p in patterns])]
|
||||||
|
|
||||||
# There isn't any matching files. Don't unzip anything.
|
# There isn't any matching files. Don't unzip anything.
|
||||||
if not filtered:
|
if not filtered:
|
||||||
return
|
return
|
||||||
cmd.extend(filtered)
|
input_zip.extractall(dirname, filtered)
|
||||||
|
else:
|
||||||
RunAndCheckOutput(cmd)
|
input_zip.extractall(dirname)
|
||||||
|
|
||||||
|
|
||||||
def UnzipTemp(filename, patterns=None):
|
def UnzipTemp(filename, patterns=None):
|
||||||
|
Reference in New Issue
Block a user