Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/disk
diff options
context:
space:
mode:
authorWerner Llácer <wllacer@gmail.com>2022-04-25 08:57:49 +0200
committerGitHub <noreply@github.com>2022-04-25 08:57:49 +0200
commita14604a1b642e41e53b09df7b9b0eabd684045a0 (patch)
treeeeecef7e914b4e8b6c2fcf0f248b049c416d4a68 /archinstall/lib/disk
parent15c594bcbaa24a4df821b2b3489072e064ea9b23 (diff)
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
Diffstat (limited to 'archinstall/lib/disk')
-rw-r--r--archinstall/lib/disk/helpers.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/archinstall/lib/disk/helpers.py b/archinstall/lib/disk/helpers.py
index 30c47666..2f73b2bd 100644
--- a/archinstall/lib/disk/helpers.py
+++ b/archinstall/lib/disk/helpers.py
@@ -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