Created a routine to check if a partition includes a certain mountpoint (#1069)
For a btrfs volume with a subvolume to be mounted on /, we will not generate a keyfile anymore
This commit is contained in:
parent
15c594bcba
commit
a14604a1b6
|
|
@ -440,3 +440,35 @@ def convert_device_to_uuid(path :str) -> str:
|
|||
time.sleep(storage['DISK_TIMEOUTS'])
|
||||
|
||||
raise DiskError(f"Could not retrieve the UUID of {path} within a timely manner.")
|
||||
|
||||
def has_mountpoint(partition: Union[dict,Partition,MapperDev], target: str, strict: bool = True) -> bool:
|
||||
""" Determine if a certain partition is mounted (or has a mountpoint) as specific target (path)
|
||||
Coded for clarity rather than performance
|
||||
|
||||
Input parms:
|
||||
:parm partition the partition we check
|
||||
:type Either a Partition object or a dict with the contents of a partition definiton in the disk_layouts schema
|
||||
|
||||
:parm target (a string representing a mount path we want to check for.
|
||||
:type str
|
||||
|
||||
:parm strict if the check will be strict, target is exactly the mountpoint, or no, where the target is a leaf (f.i. to check if it is in /mnt/archinstall/). Not available for root check ('/') for obvious reasons
|
||||
|
||||
"""
|
||||
# we create the mountpoint list
|
||||
if isinstance(partition,dict):
|
||||
subvols = partition.get('btrfs',{}).get('subvolumes',{})
|
||||
mountpoints = [partition.get('mountpoint'),] + [subvols[subvol] if isinstance(subvols[subvol],str) or not subvols[subvol] else subvols[subvol].get('mountpoint') for subvol in subvols]
|
||||
else:
|
||||
mountpoints = [partition.mountpoint,] + [subvol.target for subvol in partition.subvolumes]
|
||||
# we check
|
||||
if strict or target == '/':
|
||||
if target in mountpoints:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
for mp in mountpoints:
|
||||
if mp and mp.endswith(target):
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from ..menu import Menu
|
|||
from ..output import log
|
||||
|
||||
from ..disk.validators import fs_types
|
||||
from ..disk.helpers import has_mountpoint
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..disk import BlockDevice
|
||||
|
|
@ -298,7 +299,7 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
|
|||
|
||||
elif task == set_btrfs_subvolumes:
|
||||
from .subvolume_config import SubvolumeList
|
||||
|
||||
|
||||
# TODO get preexisting partitions
|
||||
title = _('{}\n\nSelect which partition to set subvolumes on').format(current_layout)
|
||||
partition = select_partition(title, block_device_struct["partitions"],filter=lambda x:True if x.get('filesystem',{}).get('format') == 'btrfs' else False)
|
||||
|
|
@ -325,7 +326,7 @@ def select_encrypted_partitions(block_devices: dict, password: str) -> dict:
|
|||
partition['encrypted'] = True
|
||||
partition['!password'] = password
|
||||
|
||||
if partition['mountpoint'] != '/':
|
||||
if not has_mountpoint(partition,'/'):
|
||||
# Tell the upcoming steps to generate a key-file for non root mounts.
|
||||
partition['generate-encryption-key-file'] = True
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue