Merge changes I9c1a5346,I0a9d2c58
* changes: Fix python3.11's support for zip64 Search for partition maps in IMAGES dir as well
This commit is contained in:
commit
5c73eb33db
2 changed files with 18 additions and 4 deletions
|
@ -2126,17 +2126,28 @@ def UnzipToDir(filename, dirname, patterns=None):
|
||||||
"""
|
"""
|
||||||
with zipfile.ZipFile(filename, allowZip64=True, mode="r") as input_zip:
|
with zipfile.ZipFile(filename, allowZip64=True, mode="r") as input_zip:
|
||||||
# Filter out non-matching patterns. unzip will complain otherwise.
|
# Filter out non-matching patterns. unzip will complain otherwise.
|
||||||
|
entries = input_zip.infolist()
|
||||||
|
# b/283033491
|
||||||
|
# Per https://en.wikipedia.org/wiki/ZIP_(file_format)#Central_directory_file_header
|
||||||
|
# In zip64 mode, central directory record's header_offset field might be
|
||||||
|
# set to 0xFFFFFFFF if header offset is > 2^32. In this case, the extra
|
||||||
|
# fields will contain an 8 byte little endian integer at offset 20
|
||||||
|
# to indicate the actual local header offset.
|
||||||
|
# As of python3.11, python does not handle zip64 central directories
|
||||||
|
# correctly, so we will manually do the parsing here.
|
||||||
|
for entry in entries:
|
||||||
|
if entry.header_offset == 0xFFFFFFFF and len(entry.extra) >= 28:
|
||||||
|
entry.header_offset = int.from_bytes(entry.extra[20:28], "little")
|
||||||
if patterns is not None:
|
if patterns is not None:
|
||||||
names = input_zip.namelist()
|
filtered = [info for info in entries if any(
|
||||||
filtered = [name for name in names if any(
|
[fnmatch.fnmatch(info.filename, p) for p in patterns])]
|
||||||
[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
|
||||||
input_zip.extractall(dirname, filtered)
|
input_zip.extractall(dirname, filtered)
|
||||||
else:
|
else:
|
||||||
input_zip.extractall(dirname)
|
input_zip.extractall(dirname, entries)
|
||||||
|
|
||||||
|
|
||||||
def UnzipTemp(filename, patterns=None):
|
def UnzipTemp(filename, patterns=None):
|
||||||
|
|
|
@ -760,6 +760,9 @@ def GetPartitionImages(target_files_dir: str, ab_partitions, allow_empty=True):
|
||||||
|
|
||||||
def LocatePartitionMap(target_files_dir: str, partition: str):
|
def LocatePartitionMap(target_files_dir: str, partition: str):
|
||||||
path = os.path.join(target_files_dir, "RADIO", partition + ".map")
|
path = os.path.join(target_files_dir, "RADIO", partition + ".map")
|
||||||
|
if os.path.exists(path):
|
||||||
|
return path
|
||||||
|
path = os.path.join(target_files_dir, "IMAGES", partition + ".map")
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
return path
|
return path
|
||||||
return ""
|
return ""
|
||||||
|
|
Loading…
Reference in a new issue