refuse to add a boot partition if it means shrinking a partition by more than 50%

This commit is contained in:
Michael Hudson-Doyle 2022-03-18 16:23:56 +13:00
parent fd0a7954e4
commit 58d9670372
2 changed files with 6 additions and 4 deletions

View File

@ -208,6 +208,8 @@ def get_add_part_plan(device, *, spec, args):
largest_i, largest_part = max(
enumerate(partitions),
key=lambda i_p: i_p[1].size)
if size > largest_part.size // 2:
return None
create_part_plan.offset = largest_part.offset
return MultiStepPlan(plans=[
SlidePlan(

View File

@ -279,9 +279,9 @@ class TestFilesystemManipulator(unittest.TestCase):
def test_add_boot_BIOS_full_resizes_larger(self):
manipulator = make_manipulator(Bootloader.BIOS)
# 402MiB so that the space available for partitioning (400MiB)
# 2002MiB so that the space available for partitioning (2000MiB)
# divided by 4 is an whole number of megabytes.
disk = make_disk(manipulator.model, preserve=True, size=402*MiB)
disk = make_disk(manipulator.model, preserve=True, size=2002*MiB)
part_smaller = make_partition(
manipulator.model, disk, size=gaps.largest_gap_size(disk)//4)
part_larger = make_partition(
@ -354,9 +354,9 @@ class TestFilesystemManipulator(unittest.TestCase):
def test_add_boot_UEFI_full_resizes_larger(self):
manipulator = make_manipulator(Bootloader.UEFI)
# 402MiB so that the space available for partitioning (400MiB)
# 2002MiB so that the space available for partitioning (2000MiB)
# divided by 4 is an whole number of megabytes.
disk = make_disk(manipulator.model, preserve=True, size=402*MiB)
disk = make_disk(manipulator.model, preserve=True, size=2002*MiB)
part_smaller = make_partition(
manipulator.model, disk, size=gaps.largest_gap_size(disk)//4)
part_larger = make_partition(