releasetools: Don't return ZipFile from common.UnzipTemp().
In addition to the unzipping work, common.UnzipTemp() kindly bundles an open ZipFile object as part of the return value. It doesn't look very helpful to the callers though. It also looks less obvious that the caller needs to properly close the handle (missing the close here is benign though). This CL just removes the ZipFile object out of the return value, and leaves the work to callers. Test: `m dist` on both of A/B and non-A/B target. Test: python -m unittest test_add_img_to_target_files Test: python -m unittest test_common Test: python -m unittest test_ota_from_target_files Test: Check the callers to common.UnzipTemp() in code search. Change-Id: Id47da3fd42a0e76d6ae8851f05780db319ee48cf
This commit is contained in:
@@ -632,23 +632,26 @@ def AddImagesToTargetFiles(filename):
|
||||
The images will be created under IMAGES/ in the input target_files.zip.
|
||||
|
||||
Args:
|
||||
filename: the target_files.zip, or the zip root directory.
|
||||
filename: the target_files.zip, or the zip root directory.
|
||||
"""
|
||||
if os.path.isdir(filename):
|
||||
OPTIONS.input_tmp = os.path.abspath(filename)
|
||||
input_zip = None
|
||||
else:
|
||||
OPTIONS.input_tmp, input_zip = common.UnzipTemp(filename)
|
||||
OPTIONS.input_tmp = common.UnzipTemp(filename)
|
||||
|
||||
if not OPTIONS.add_missing:
|
||||
if os.path.isdir(os.path.join(OPTIONS.input_tmp, "IMAGES")):
|
||||
print("target_files appears to already contain images.")
|
||||
sys.exit(1)
|
||||
|
||||
# {vendor,product}.img is unlike system.img or system_other.img. Because it could
|
||||
# be built from source, or dropped into target_files.zip as a prebuilt blob.
|
||||
# We consider either of them as {vendor,product}.img being available, which could
|
||||
# be used when generating vbmeta.img for AVB.
|
||||
OPTIONS.info_dict = common.LoadInfoDict(OPTIONS.input_tmp, OPTIONS.input_tmp)
|
||||
|
||||
has_recovery = OPTIONS.info_dict.get("no_recovery") != "true"
|
||||
|
||||
# {vendor,product}.img is unlike system.img or system_other.img. Because it
|
||||
# could be built from source, or dropped into target_files.zip as a prebuilt
|
||||
# blob. We consider either of them as {vendor,product}.img being available,
|
||||
# which could be used when generating vbmeta.img for AVB.
|
||||
has_vendor = (os.path.isdir(os.path.join(OPTIONS.input_tmp, "VENDOR")) or
|
||||
os.path.exists(os.path.join(OPTIONS.input_tmp, "IMAGES",
|
||||
"vendor.img")))
|
||||
@@ -658,16 +661,14 @@ def AddImagesToTargetFiles(filename):
|
||||
has_system_other = os.path.isdir(os.path.join(OPTIONS.input_tmp,
|
||||
"SYSTEM_OTHER"))
|
||||
|
||||
if input_zip:
|
||||
OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.input_tmp)
|
||||
|
||||
common.ZipClose(input_zip)
|
||||
# Set up the output destination. It writes to the given directory for dir
|
||||
# mode; otherwise appends to the given ZIP.
|
||||
if os.path.isdir(filename):
|
||||
output_zip = None
|
||||
else:
|
||||
output_zip = zipfile.ZipFile(filename, "a",
|
||||
compression=zipfile.ZIP_DEFLATED,
|
||||
allowZip64=True)
|
||||
else:
|
||||
OPTIONS.info_dict = common.LoadInfoDict(filename, filename)
|
||||
output_zip = None
|
||||
|
||||
# Always make input_tmp/IMAGES available, since we may stage boot / recovery
|
||||
# images there even under zip mode. The directory will be cleaned up as part
|
||||
@@ -676,8 +677,6 @@ def AddImagesToTargetFiles(filename):
|
||||
if not os.path.isdir(images_dir):
|
||||
os.makedirs(images_dir)
|
||||
|
||||
has_recovery = (OPTIONS.info_dict.get("no_recovery") != "true")
|
||||
|
||||
# A map between partition names and their paths, which could be used when
|
||||
# generating AVB vbmeta image.
|
||||
partitions = dict()
|
||||
|
Reference in New Issue
Block a user