From a652c00c8eb0906ff6b9f81c9d1a7972ce973ad0 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 1 Mar 2018 19:31:38 -0800 Subject: [PATCH] releasetools: Fix a mismatching close. There's a mismatch in WriteABOTAPackageWithBrilloScript(). temp_zip_file = tempfile.NamedTemporaryFile() ... common.ZipClose(temp_zip_file) It's benign since common.ZipClose() happens to be calling "temp_zip_file.close()". This CL moves the use of tempfile to common.MakeTempFile(), so that the tempfile will be cleaned up automatically as part of the call to common.Cleanup(). (Not fixing the close() directly, since the nearby lines will be refactored into another function shortly.) Also remove one assert in the same function, which trivially holds in the current code. Test: Generate an A/B OTA. Change-Id: I53b375d1150820de718dec0ead55abf5f4951071 --- tools/releasetools/ota_from_target_files.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py index 7d76dcb43..dd8dcd0ce 100755 --- a/tools/releasetools/ota_from_target_files.py +++ b/tools/releasetools/ota_from_target_files.py @@ -1354,8 +1354,8 @@ def WriteABOTAPackageWithBrilloScript(target_file, output_file, return value # Stage the output zip package for package signing. - temp_zip_file = tempfile.NamedTemporaryFile() - output_zip = zipfile.ZipFile(temp_zip_file, "w", + staging_file = common.MakeTempFile(suffix='.zip') + output_zip = zipfile.ZipFile(staging_file, "w", compression=zipfile.ZIP_DEFLATED) if source_file is not None: @@ -1410,10 +1410,6 @@ def WriteABOTAPackageWithBrilloScript(target_file, output_file, else: print("Warning: cannot find care map file in target_file package") - # source_info must be None for full OTAs. - if source_file is None: - assert source_info is None - AddCompatibilityArchiveIfTrebleEnabled( target_zip, output_zip, target_info, source_info) @@ -1431,8 +1427,7 @@ def WriteABOTAPackageWithBrilloScript(target_file, output_file, # compute the ZIP entry offsets, write back the final metadata and do the # final signing. prelim_signing = common.MakeTempFile(suffix='.zip') - SignOutput(temp_zip_file.name, prelim_signing) - common.ZipClose(temp_zip_file) + SignOutput(staging_file, prelim_signing) # Open the signed zip. Compute the final metadata that's needed for streaming. prelim_signing_zip = zipfile.ZipFile(prelim_signing, 'r')