From 940485b7cb6a6eb36b7eead38658636672710318 Mon Sep 17 00:00:00 2001 From: Volodymyr Babchuk Date: Mon, 5 Aug 2024 21:22:15 +0300 Subject: [PATCH] rouge: workaround changes in gpt-image gpt-image is package for working with GPTs. We use it to create partition layout in rouge. To properly write sub-images into final image, we need to know offset for every partition. To do this, we read "first_lba" field in Partition object. Problem is that in gpt-image 0.9.0 this property contains zero and we need to read "first_lba_staged" property instead. Also, we need to support old installation, so we just can't replace "first_lba" with "first_lba_staged" in the code. Instead we should try the new field first and then fall back to the old one. Tested with both gpt-image 0.9.0 and gpt-image 0.8.1 Signed-off-by: Volodymyr Babchuk Reviewed-by: Ruslan Shymkevych Tested-by: Mykhailo Androsiuk --- moulin/rouge/gpti.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/moulin/rouge/gpti.py b/moulin/rouge/gpti.py index 6f28679..9488a77 100644 --- a/moulin/rouge/gpti.py +++ b/moulin/rouge/gpti.py @@ -47,7 +47,19 @@ def fixup_partition_table(partitions: List[Any], sector_size=512) -> Tuple[List[ part.gpt_guid, DEFAULT_ALIGNMENT // sector_size) ) pe = table.partitions.entries[-1] - start = pe.first_lba * sector_size + + # Workaround for gpt-image: in release 0.9.0 they changed how first LBA + # is stored. Now we need to read `first_lba_staged` property. Problem + # is that we don't know which version is installed on the user's + # machine. So, first we try to read `first_lba_staged` and if it fails + # - old `first_lba` property. + first_lba = 0 + try: + first_lba = pe.first_lba_staged + except AttributeError: + first_lba = pe.first_lba + + start = first_lba * sector_size ret.append(part._replace(start=start, size=size)) end = start + size