Skip to content

Commit

Permalink
Add get_loop_devices() (#2698)
Browse files Browse the repository at this point in the history
  • Loading branch information
codefiles authored Sep 25, 2024
1 parent 8e9b1bc commit 8db3c7d
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions archinstall/lib/disk/device_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from parted import (
Disk, Geometry, FileSystem,
PartitionException, DiskException,
PartitionException, DiskException, IOException,
getDevice, getAllDevices, newDisk, freshDisk, Partition, Device
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8db3c7d

Please sign in to comment.