calculation partition size use compressed image size

If dynamic partitioning is enabled and the partition size is not set,
du will be used to calculate the partition size.

For compressed file systems, it's better to use the compressed size
to avoid wasting space.

Bug:174816929
Test: erofs image size is smaller than the original file
Change-Id: I1deda85d312c19620680531223fffcfb815e5fd4
Signed-off-by: Huang Jianan <huangjianan@oppo.com>
This commit is contained in:
Huang Jianan
2020-12-04 16:58:24 +08:00
committed by jianan huang
parent 62d926e2fe
commit 35f015ea5e

View File

@@ -427,7 +427,16 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
if (prop_dict.get("use_dynamic_partition_size") == "true" and
"partition_size" not in prop_dict):
# If partition_size is not defined, use output of `du' + reserved_size.
size = GetDiskUsage(in_dir)
# For compressed file system, it's better to use the compressed size to avoid wasting space.
if fs_type.startswith("erofs"):
tmp_dict = prop_dict.copy()
if "erofs_sparse_flag" in tmp_dict:
tmp_dict.pop("erofs_sparse_flag")
BuildImageMkfs(in_dir, tmp_dict, out_file, target_out, fs_config)
size = GetDiskUsage(out_file)
os.remove(out_file)
else:
size = GetDiskUsage(in_dir)
logger.info(
"The tree size of %s is %d MB.", in_dir, size // BYTES_IN_MB)
# If not specified, give us 16MB margin for GetDiskUsage error ...