Merge "Remove unnecesasry use of ZipClose()" am: 6974223827

Original change: https://android-review.googlesource.com/c/platform/build/+/2246356

Change-Id: I68032b8a98e90b47a672dc696d114d0eb793d6a4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2022-10-17 23:22:04 +00:00
committed by Automerger Merge Worker

View File

@@ -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)