Unsparse images before generating OTA

Test: th
Bug: 283172692
Change-Id: Ie6d3dc704fd9a8c107e2888222e4c2bf804dad3e
This commit is contained in:
Kelvin Zhang
2023-05-19 13:12:59 -07:00
parent d104c386f6
commit 2268091521
2 changed files with 32 additions and 3 deletions

View File

@@ -2782,6 +2782,8 @@ def MakeTempDir(prefix='tmp', suffix=''):
def Cleanup():
for i in OPTIONS.tempfiles:
if not os.path.exists(i):
continue
if os.path.isdir(i):
shutil.rmtree(i, ignore_errors=True)
else:
@@ -4117,6 +4119,17 @@ def IsSparseImage(filepath):
return fp.read(4) == b'\x3A\xFF\x26\xED'
def UnsparseImage(filepath, target_path=None):
if not IsSparseImage(filepath):
return
if target_path is None:
tmp_img = MakeTempFile(suffix=".img")
RunAndCheckOutput(["simg2img", filepath, tmp_img])
os.rename(tmp_img, filepath)
else:
RunAndCheckOutput(["simg2img", filepath, target_path])
def ParseUpdateEngineConfig(path: str):
"""Parse the update_engine config stored in file `path`
Args