Unsparse images before generating OTA
Test: th Bug: 283172692 Change-Id: Ie6d3dc704fd9a8c107e2888222e4c2bf804dad3e
This commit is contained in:
@@ -2782,6 +2782,8 @@ def MakeTempDir(prefix='tmp', suffix=''):
|
|||||||
|
|
||||||
def Cleanup():
|
def Cleanup():
|
||||||
for i in OPTIONS.tempfiles:
|
for i in OPTIONS.tempfiles:
|
||||||
|
if not os.path.exists(i):
|
||||||
|
continue
|
||||||
if os.path.isdir(i):
|
if os.path.isdir(i):
|
||||||
shutil.rmtree(i, ignore_errors=True)
|
shutil.rmtree(i, ignore_errors=True)
|
||||||
else:
|
else:
|
||||||
@@ -4117,6 +4119,17 @@ def IsSparseImage(filepath):
|
|||||||
return fp.read(4) == b'\x3A\xFF\x26\xED'
|
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):
|
def ParseUpdateEngineConfig(path: str):
|
||||||
"""Parse the update_engine config stored in file `path`
|
"""Parse the update_engine config stored in file `path`
|
||||||
Args
|
Args
|
||||||
|
@@ -48,6 +48,7 @@ METADATA_PROTO_NAME = 'META-INF/com/android/metadata.pb'
|
|||||||
UNZIP_PATTERN = ['IMAGES/*', 'META/*', 'OTA/*',
|
UNZIP_PATTERN = ['IMAGES/*', 'META/*', 'OTA/*',
|
||||||
'RADIO/*', '*/build.prop', '*/default.prop', '*/build.default', "*/etc/vintf/*"]
|
'RADIO/*', '*/build.prop', '*/default.prop', '*/build.default', "*/etc/vintf/*"]
|
||||||
SECURITY_PATCH_LEVEL_PROP_NAME = "ro.build.version.security_patch"
|
SECURITY_PATCH_LEVEL_PROP_NAME = "ro.build.version.security_patch"
|
||||||
|
TARGET_FILES_IMAGES_SUBDIR = ["IMAGES", "PREBUILT_IMAGES", "RADIO"]
|
||||||
|
|
||||||
|
|
||||||
def FinalizeMetadata(metadata, input_file, output_file, needed_property_files=None, package_key=None, pw=None):
|
def FinalizeMetadata(metadata, input_file, output_file, needed_property_files=None, package_key=None, pw=None):
|
||||||
@@ -727,6 +728,15 @@ def ExtractTargetFiles(path: str):
|
|||||||
return path
|
return path
|
||||||
extracted_dir = common.MakeTempDir("target_files")
|
extracted_dir = common.MakeTempDir("target_files")
|
||||||
common.UnzipToDir(path, extracted_dir, UNZIP_PATTERN + [""])
|
common.UnzipToDir(path, extracted_dir, UNZIP_PATTERN + [""])
|
||||||
|
for subdir in TARGET_FILES_IMAGES_SUBDIR:
|
||||||
|
image_dir = os.path.join(extracted_dir, subdir)
|
||||||
|
if not os.path.exists(image_dir):
|
||||||
|
continue
|
||||||
|
for filename in os.listdir(image_dir):
|
||||||
|
if not filename.endswith(".img"):
|
||||||
|
continue
|
||||||
|
common.UnsparseImage(os.path.join(image_dir, filename))
|
||||||
|
|
||||||
return extracted_dir
|
return extracted_dir
|
||||||
|
|
||||||
|
|
||||||
@@ -1047,12 +1057,18 @@ def Fnmatch(filename, pattersn):
|
|||||||
|
|
||||||
def CopyTargetFilesDir(input_dir):
|
def CopyTargetFilesDir(input_dir):
|
||||||
output_dir = common.MakeTempDir("target_files")
|
output_dir = common.MakeTempDir("target_files")
|
||||||
IMAGES_DIR = ["IMAGES", "PREBUILT_IMAGES", "RADIO"]
|
|
||||||
for subdir in IMAGES_DIR:
|
def SymlinkIfNotSparse(src, dst):
|
||||||
|
if common.IsSparseImage(src):
|
||||||
|
return common.UnsparseImage(src, dst)
|
||||||
|
else:
|
||||||
|
return os.link(src, dst)
|
||||||
|
|
||||||
|
for subdir in TARGET_FILES_IMAGES_SUBDIR:
|
||||||
if not os.path.exists(os.path.join(input_dir, subdir)):
|
if not os.path.exists(os.path.join(input_dir, subdir)):
|
||||||
continue
|
continue
|
||||||
shutil.copytree(os.path.join(input_dir, subdir), os.path.join(
|
shutil.copytree(os.path.join(input_dir, subdir), os.path.join(
|
||||||
output_dir, subdir), dirs_exist_ok=True, copy_function=os.link)
|
output_dir, subdir), dirs_exist_ok=True, copy_function=SymlinkIfNotSparse)
|
||||||
shutil.copytree(os.path.join(input_dir, "META"), os.path.join(
|
shutil.copytree(os.path.join(input_dir, "META"), os.path.join(
|
||||||
output_dir, "META"), dirs_exist_ok=True)
|
output_dir, "META"), dirs_exist_ok=True)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user