From eb147e051ed0f762fd36de73fbc34b5087bba69d Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Fri, 21 Oct 2022 10:53:21 -0700 Subject: [PATCH] Fix ota build error when using boot variable files When performing a deep copy of info dict, input_file is serialized as filename. Make ExtractFromInputFile support reading from filename of a ZipFile. Test: build OTA with partner provided target_files Bug: 253549364 Change-Id: I366a076c32d638d61b83a1df9bf864807cf5257c --- tools/releasetools/common.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index 3c5ba10d67..715802faae 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -723,7 +723,16 @@ def ExtractFromInputFile(input_file, fn): with open(tmp_file, 'wb') as f: f.write(input_file.read(fn)) return tmp_file + elif zipfile.is_zipfile(input_file): + with zipfile.ZipFile(input_file, "r", allowZip64=True) as zfp: + tmp_file = MakeTempFile(os.path.basename(fn)) + with open(tmp_file, "wb") as fp: + fp.write(zfp.read(fn)) + return tmp_file else: + if not os.path.isdir(input_file): + raise ValueError( + "Invalid input_file, accepted inputs are ZipFile object, path to .zip file on disk, or path to extracted directory. Actual: " + input_file) file = os.path.join(input_file, *fn.split("/")) if not os.path.exists(file): raise KeyError(fn)