summaryrefslogtreecommitdiffstats
path: root/src/utils/disk.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-03-11 09:44:38 +0100
committerlupoDharkael <izhe@hotmail.es>2024-03-21 10:29:13 +0100
commitddf08779ae8db05a75d51e063f507d1c3bfa148e (patch)
tree87e6bd0da2cfe65cc9183e080a3ec822af33757d /src/utils/disk.py
parenta3ffdf2370899d060f6f708e2d6e31ae5b7b54bc (diff)
utils: add disk index checks in get_partition_device
Control the possibility of a bad disk index. Handle the checks in a similar fashion to the get_efi_partition function.
Diffstat (limited to 'src/utils/disk.py')
-rw-r--r--src/utils/disk.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/utils/disk.py b/src/utils/disk.py
index 0848cff..b4541cc 100644
--- a/src/utils/disk.py
+++ b/src/utils/disk.py
@@ -27,7 +27,11 @@ def get_partition_device(disknum, partnum):
"""
Returns the device path, given a disk and partition number
"""
- disk = get_disks()[disknum-1]
+ disk_index = disknum - 1
+ if disk_index < 0 or disk_index >= len(get_disks()):
+ raise ValueError(f'Invalid disk number {disknum}, {len(get_disks())} disks available.')
+
+ disk = get_disks()[disk_index]
cxt = fdisk.Context(f'/dev/{disk}')
for pa in cxt.partitions: