diff options
author | Kelvin Zhang <zhangkelvin@google.com> | 2022-10-10 10:58:57 -0700 |
---|---|---|
committer | Kelvin Zhang <zhangkelvin@google.com> | 2022-10-17 10:04:45 -0700 |
commit | 2e1ff6e26269b03d0f0d23d1929e8820bceb2933 (patch) | |
tree | c6fb190af28019a93e1b828696cb2eb3e869d414 | |
parent | cd91bec2ca8835199f408d20f69c222693100544 (diff) | |
download | build-2e1ff6e26269b03d0f0d23d1929e8820bceb2933.tar.gz |
Remove unnecesasry use of ZipClose()
ZipClose() was introduced to work with large zip without switching to
ZIP64. It is a hacky patch. Now we have moved to python3 and zip64
completely, no need to keep using it.
Test: th
Bug: 246504616
Change-Id: I1ff15171bb26887b819f655e32817627ecad1132
-rw-r--r-- | tools/releasetools/ota_utils.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/tools/releasetools/ota_utils.py b/tools/releasetools/ota_utils.py index 06349a240b..9f418749bc 100644 --- a/tools/releasetools/ota_utils.py +++ b/tools/releasetools/ota_utils.py @@ -84,17 +84,14 @@ def FinalizeMetadata(metadata, input_file, output_file, needed_property_files=No def ComputeAllPropertyFiles(input_file, needed_property_files): # Write the current metadata entry with placeholders. - with zipfile.ZipFile(input_file, allowZip64=True) as input_zip: + with zipfile.ZipFile(input_file, 'r', allowZip64=True) as input_zip: for property_files in needed_property_files: metadata.property_files[property_files.name] = property_files.Compute( input_zip) - namelist = input_zip.namelist() - if METADATA_NAME in namelist or METADATA_PROTO_NAME in namelist: - ZipDelete(input_file, [METADATA_NAME, METADATA_PROTO_NAME]) - output_zip = zipfile.ZipFile(input_file, 'a', allowZip64=True) - WriteMetadata(metadata, output_zip) - ZipClose(output_zip) + ZipDelete(input_file, [METADATA_NAME, METADATA_PROTO_NAME], True) + with zipfile.ZipFile(input_file, 'a', allowZip64=True) as output_zip: + WriteMetadata(metadata, output_zip) if no_signing: return input_file @@ -104,7 +101,7 @@ def FinalizeMetadata(metadata, input_file, output_file, needed_property_files=No return prelim_signing def FinalizeAllPropertyFiles(prelim_signing, needed_property_files): - with zipfile.ZipFile(prelim_signing, allowZip64=True) as prelim_signing_zip: + with zipfile.ZipFile(prelim_signing, 'r', allowZip64=True) as prelim_signing_zip: for property_files in needed_property_files: metadata.property_files[property_files.name] = property_files.Finalize( prelim_signing_zip, @@ -130,9 +127,8 @@ def FinalizeMetadata(metadata, input_file, output_file, needed_property_files=No # Replace the METADATA entry. ZipDelete(prelim_signing, [METADATA_NAME, METADATA_PROTO_NAME]) - output_zip = zipfile.ZipFile(prelim_signing, 'a', allowZip64=True) - WriteMetadata(metadata, output_zip) - ZipClose(output_zip) + with zipfile.ZipFile(prelim_signing, 'a', allowZip64=True) as output_zip: + WriteMetadata(metadata, output_zip) # Re-sign the package after updating the metadata entry. if no_signing: @@ -591,7 +587,7 @@ class PropertyFiles(object): else: tokens.append(ComputeEntryOffsetSize(METADATA_NAME)) if METADATA_PROTO_NAME in zip_file.namelist(): - tokens.append(ComputeEntryOffsetSize(METADATA_PROTO_NAME)) + tokens.append(ComputeEntryOffsetSize(METADATA_PROTO_NAME)) return ','.join(tokens) |