From 70876143b5c8f2ea1912d551d40de5af7a55e1b2 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Wed, 9 Feb 2022 16:05:29 -0800 Subject: [PATCH] Fix signing failure when no entry to convert to store zip -d doesn't work when no entry names specified. So if the list of entry is empty, just skip calling zip -d. Bug: 218438888 Test: th Change-Id: Ie4419b9d6fdc2780255c6f12f9f4d35e5c0a7b26 --- tools/releasetools/add_img_to_target_files.py | 7 ++++--- tools/releasetools/common.py | 3 +++ tools/releasetools/sign_target_files_apks.py | 3 --- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py index 9a9fba148d..30006baf6c 100644 --- a/tools/releasetools/add_img_to_target_files.py +++ b/tools/releasetools/add_img_to_target_files.py @@ -64,7 +64,7 @@ import verity_utils import ota_metadata_pb2 from apex_utils import GetApexInfoFromTargetFiles -from common import AddCareMapForAbOta +from common import AddCareMapForAbOta, ZipDelete if sys.hexversion < 0x02070000: print("Python 2.7 or newer is required.", file=sys.stderr) @@ -1034,9 +1034,10 @@ def OptimizeCompressedEntries(zipfile_path): if zinfo.compress_size > zinfo.file_size * 0.80 and zinfo.compress_type != zipfile.ZIP_STORED: entries_to_store.append(zinfo) zfp.extract(zinfo, tmpdir) + if len(entries_to_store) == 0: + return # Remove these entries, then re-add them as ZIP_STORED - common.RunAndCheckOutput( - ["zip", "-d", zipfile_path] + [entry.filename for entry in entries_to_store]) + ZipDelete(zipfile_path, [entry.filename for entry in entries_to_store]) with zipfile.ZipFile(zipfile_path, "a", allowZip64=True) as zfp: for entry in entries_to_store: zfp.write(os.path.join(tmpdir, entry.filename), entry.filename, compress_type=zipfile.ZIP_STORED) diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index 686102a58d..850619940b 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -2818,6 +2818,9 @@ def ZipDelete(zip_filename, entries): """ if isinstance(entries, str): entries = [entries] + # If list is empty, nothing to do + if not entries: + return cmd = ["zip", "-d", zip_filename] + entries RunAndCheckOutput(cmd) diff --git a/tools/releasetools/sign_target_files_apks.py b/tools/releasetools/sign_target_files_apks.py index 5b16d803cf..adba866371 100755 --- a/tools/releasetools/sign_target_files_apks.py +++ b/tools/releasetools/sign_target_files_apks.py @@ -1521,8 +1521,5 @@ def main(argv): if __name__ == '__main__': try: main(sys.argv[1:]) - except common.ExternalError as e: - print("\n ERROR: %s\n" % (e,)) - raise finally: common.Cleanup()