From 8db3c7d65d9963112e1361b431bfd5e2d53455eb Mon Sep 17 00:00:00 2001 From: codefiles <11915375+codefiles@users.noreply.github.com> Date: Wed, 25 Sep 2024 09:02:51 -0400 Subject: [PATCH] Add get_loop_devices() (#2698) --- archinstall/lib/disk/device_handler.py | 35 +++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/archinstall/lib/disk/device_handler.py b/archinstall/lib/disk/device_handler.py index 839a050f0..67362c913 100644 --- a/archinstall/lib/disk/device_handler.py +++ b/archinstall/lib/disk/device_handler.py @@ -10,7 +10,7 @@ from parted import ( Disk, Geometry, FileSystem, - PartitionException, DiskException, + PartitionException, DiskException, IOException, getDevice, getAllDevices, newDisk, freshDisk, Partition, Device ) @@ -50,14 +50,7 @@ def load_devices(self) -> None: self.udev_sync() all_lsblk_info = get_all_lsblk_info() devices = getAllDevices() - - try: - loop_devices = SysCommand(['losetup', '-a']) - for ld_info in str(loop_devices).splitlines(): - loop_device = getDevice(ld_info.split(':', maxsplit=1)[0]) - devices.append(loop_device) - except Exception as err: - debug(f'Failed to get loop devices: {err}') + devices.extend(self.get_loop_devices()) for device in devices: dev_lsblk_info = find_lsblk_info(device.path, all_lsblk_info) @@ -111,6 +104,30 @@ def load_devices(self) -> None: self._devices = block_devices + @staticmethod + def get_loop_devices() -> list[Device]: + devices = [] + + try: + loop_devices = SysCommand(['losetup', '-a']) + except SysCallError as err: + debug(f'Failed to get loop devices: {err}') + else: + for ld_info in str(loop_devices).splitlines(): + try: + loop_device_path, _ = ld_info.split(':', maxsplit=1) + except ValueError: + continue + + try: + loop_device = getDevice(loop_device_path) + except IOException as err: + debug(f'Failed to get loop device: {err}') + else: + devices.append(loop_device) + + return devices + def _determine_fs_type( self, partition: Partition,