Fix `mountpoint` for pre-mounted disk configuration (#2113)

* Fix `mountpoint` for pre-mounted disk configuration

* Add missing commas
This commit is contained in:
codefiles 2023-09-26 04:57:45 -04:00 committed by GitHub
parent c427391543
commit 717a22371f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 22 deletions

View File

@ -594,7 +594,9 @@ class DeviceHandler(object):
if is_subpath(mountpoint, base_mountpoint): if is_subpath(mountpoint, base_mountpoint):
path = Path(part_info.disk.device.path) path = Path(part_info.disk.device.path)
part_mods.setdefault(path, []) part_mods.setdefault(path, [])
part_mods[path].append(PartitionModification.from_existing_partition(part_info)) part_mod = PartitionModification.from_existing_partition(part_info)
part_mod.mountpoint = mountpoint.root / mountpoint.relative_to(base_mountpoint)
part_mods[path].append(part_mod)
break break
device_mods: List[DeviceModification] = [] device_mods: List[DeviceModification] = []

View File

@ -42,12 +42,6 @@ class DiskLayoutType(Enum):
class DiskLayoutConfiguration: class DiskLayoutConfiguration:
config_type: DiskLayoutType config_type: DiskLayoutType
device_modifications: List[DeviceModification] = field(default_factory=list) device_modifications: List[DeviceModification] = field(default_factory=list)
# used for pre-mounted config
relative_mountpoint: Optional[Path] = None
def __post_init__(self):
if self.config_type == DiskLayoutType.Pre_mount and self.relative_mountpoint is None:
raise ValueError('Must set a relative mountpoint when layout type is pre-mount"')
def json(self) -> Dict[str, Any]: def json(self) -> Dict[str, Any]:
return { return {
@ -487,10 +481,8 @@ class SubvolumeModification:
raise ValueError('Mountpoint is not specified') raise ValueError('Mountpoint is not specified')
def is_root(self, relative_mountpoint: Optional[Path] = None) -> bool: def is_root(self) -> bool:
if self.mountpoint: if self.mountpoint:
if relative_mountpoint is not None:
return self.mountpoint.relative_to(relative_mountpoint) == Path('.')
return self.mountpoint == Path('/') return self.mountpoint == Path('/')
return False return False
@ -742,14 +734,12 @@ class PartitionModification:
""" """
return any(set(self.flags) & set(self._boot_indicator_flags)) return any(set(self.flags) & set(self._boot_indicator_flags))
def is_root(self, relative_mountpoint: Optional[Path] = None) -> bool: def is_root(self) -> bool:
if relative_mountpoint is not None and self.mountpoint is not None: if self.mountpoint is not None:
return self.mountpoint.relative_to(relative_mountpoint) == Path('.')
elif self.mountpoint is not None:
return Path('/') == self.mountpoint return Path('/') == self.mountpoint
else: else:
for subvol in self.btrfs_subvols: for subvol in self.btrfs_subvols:
if subvol.is_root(relative_mountpoint): if subvol.is_root():
return True return True
return False return False
@ -861,8 +851,8 @@ class DeviceModification:
filtered = filter(lambda x: x.is_boot() and x.mountpoint, self.partitions) filtered = filter(lambda x: x.is_boot() and x.mountpoint, self.partitions)
return next(filtered, None) return next(filtered, None)
def get_root_partition(self, relative_path: Optional[Path]) -> Optional[PartitionModification]: def get_root_partition(self) -> Optional[PartitionModification]:
filtered = filter(lambda x: x.is_root(relative_path), self.partitions) filtered = filter(lambda x: x.is_root(), self.partitions)
return next(filtered, None) return next(filtered, None)
def json(self) -> Dict[str, Any]: def json(self) -> Dict[str, Any]:

View File

@ -716,7 +716,7 @@ class Installer:
def _get_root_partition(self) -> Optional[disk.PartitionModification]: def _get_root_partition(self) -> Optional[disk.PartitionModification]:
for mod in self._disk_config.device_modifications: for mod in self._disk_config.device_modifications:
if root := mod.get_root_partition(self._disk_config.relative_mountpoint): if root := mod.get_root_partition():
return root return root
return None return None
@ -903,8 +903,8 @@ class Installer:
add_options = [ add_options = [
'--target=x86_64-efi', '--target=x86_64-efi',
f'--efi-directory={efi_partition.mountpoint}' f'--efi-directory={efi_partition.mountpoint}',
f'--boot-directory={boot_partition.mountpoint if boot_partition else "/boot"}' f'--boot-directory={boot_partition.mountpoint if boot_partition else "/boot"}',
'--bootloader-id=GRUB', '--bootloader-id=GRUB',
'--removable' '--removable'
] ]

View File

@ -139,7 +139,6 @@ def select_disk_config(
return disk.DiskLayoutConfiguration( return disk.DiskLayoutConfiguration(
config_type=disk.DiskLayoutType.Pre_mount, config_type=disk.DiskLayoutType.Pre_mount,
relative_mountpoint=path,
device_modifications=mods device_modifications=mods
) )

View File

@ -9,5 +9,4 @@ mods = disk.device_handler.detect_pre_mounted_mods(root_mount_dir)
disk_config = disk.DiskLayoutConfiguration( disk_config = disk.DiskLayoutConfiguration(
disk.DiskLayoutType.Pre_mount, disk.DiskLayoutType.Pre_mount,
device_modifications=mods, device_modifications=mods,
relative_mountpoint=Path('/mnt/archinstall')
) )