move partitions around on deletion and resize

This commit is contained in:
Michael Hudson-Doyle 2022-04-01 16:04:26 +13:00
parent f24f508796
commit ce4316fc23
2 changed files with 13 additions and 2 deletions

View File

@ -168,9 +168,15 @@ class FilesystemManipulator:
if partition is not None:
if 'size' in spec:
partition.size = align_up(spec['size'])
if gaps.largest_gap_size(disk) < 0:
trailing, gap_size = \
gaps.movable_trailing_partitions_and_gap_size(partition)
new_size = align_up(spec['size'])
size_change = new_size - partition.size
if size_change > gap_size:
raise Exception("partition size too large")
partition.size = new_size
for part in trailing:
part.offset += size_change
self.delete_filesystem(partition.fs())
self.create_filesystem(partition, spec)
return

View File

@ -1404,6 +1404,11 @@ class FilesystemModel(object):
def remove_partition(self, part):
if part._fs or part._constructed_device:
raise Exception("can only remove empty partition")
from subiquity.common.filesystem.gaps import (
movable_trailing_partitions_and_gap_size,
)
for p2 in movable_trailing_partitions_and_gap_size(part)[0]:
p2.offset -= part.size
self._remove(part)
if len(part.device._partitions) == 0:
part.device.ptable = None