Merge "Unsparse images before generating OTA" am: b4406d06f0

Original change: https://android-review.googlesource.com/c/platform/build/+/2598008

Change-Id: I40ac20dd7b30d11e1eda77688718566af4c1c416
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2023-05-23 21:22:54 +00:00
committed by Automerger Merge Worker
2 changed files with 32 additions and 3 deletions

View File

@@ -2792,6 +2792,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:
@@ -4127,6 +4129,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