extract_android_ota_payload.py: don't keep temporary payload.bin file

It takes up a couple of gigabytes of space per-device.
This commit is contained in:
Dmitry Muhomor 2023-08-16 15:13:06 +03:00 committed by Daniel Micay
parent 55c15c81e6
commit 7eceea9041

View file

@ -102,10 +102,12 @@ def parse_payload(payload_f, partition, out_f):
update_metadata_pb2.InstallOperation.Type.Name(operation.type)))
def main(filename, output_dir):
is_tmp_payload_file = False
if filename.endswith('.zip'):
print("Extracting 'payload.bin' from OTA file...")
ota_zf = zipfile.ZipFile(filename)
payload_file = open(ota_zf.extract('payload.bin', output_dir), 'rb')
is_tmp_payload_file = True
else:
payload_file = open(filename, 'rb')
@ -145,6 +147,9 @@ def main(filename, output_dir):
out_f.close()
os.unlink(fname)
if is_tmp_payload_file:
os.unlink(os.path.join(output_dir, 'payload.bin'))
if __name__ == '__main__':
try:
filename = sys.argv[1]