Skip to content

Commit 781760a

Browse files
authored
Break an import cycle between lib/luks and lib/disk/device_handler (#3438)
1 parent 4ed6d0d commit 781760a

3 files changed

Lines changed: 26 additions & 25 deletions

File tree

archinstall/lib/disk/device_handler.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
find_lsblk_info,
4646
get_all_lsblk_info,
4747
get_lsblk_info,
48+
umount,
4849
)
4950

5051

@@ -257,7 +258,7 @@ def get_btrfs_info(
257258
subvol_infos.append(_BtrfsSubvolumeInfo(name, sub_vol_mountpoint))
258259

259260
if not lsblk_info.mountpoint:
260-
self.umount(dev_path)
261+
umount(dev_path)
261262

262263
return subvol_infos
263264

@@ -635,7 +636,7 @@ def create_lvm_btrfs_subvolumes(
635636
except SysCallError as err:
636637
raise DiskError(f'Could not set compress attribute at {subvol_path}: {err}')
637638

638-
self.umount(path)
639+
umount(path)
639640

640641
def create_btrfs_volumes(
641642
self,
@@ -677,7 +678,7 @@ def create_btrfs_volumes(
677678

678679
SysCommand(f"btrfs subvolume create -p {subvol_path}")
679680

680-
self.umount(dev_path)
681+
umount(dev_path)
681682

682683
if luks_handler is not None and luks_handler.mapper_dev is not None:
683684
luks_handler.lock()
@@ -710,7 +711,7 @@ def umount_all_existing(self, device_path: Path) -> None:
710711
if partition.fs_type == FilesystemType.Crypto_luks:
711712
Luks2(partition.path).lock()
712713
else:
713-
self.umount(partition.path, recursive=True)
714+
umount(partition.path, recursive=True)
714715

715716
def partition(
716717
self,
@@ -790,23 +791,6 @@ def mount(
790791
except SysCallError as err:
791792
raise DiskError(f'Could not mount {dev_path}: {command}\n{err.message}')
792793

793-
def umount(self, mountpoint: Path, recursive: bool = False) -> None:
794-
lsblk_info = get_lsblk_info(mountpoint)
795-
796-
if not lsblk_info.mountpoints:
797-
return
798-
799-
debug(f'Partition {mountpoint} is currently mounted at: {[str(m) for m in lsblk_info.mountpoints]}')
800-
801-
cmd = ['umount']
802-
803-
if recursive:
804-
cmd.append('-R')
805-
806-
for path in lsblk_info.mountpoints:
807-
debug(f'Unmounting mountpoint: {path}')
808-
SysCommand(cmd + [str(path)])
809-
810794
def detect_pre_mounted_mods(self, base_mountpoint: Path) -> list[DeviceModification]:
811795
part_mods: dict[Path, list[PartitionModification]] = {}
812796

archinstall/lib/disk/utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,21 @@ def disk_layouts() -> str:
108108
return ''
109109

110110
return lsblk_output.model_dump_json(indent=4)
111+
112+
113+
def umount(mountpoint: Path, recursive: bool = False) -> None:
114+
lsblk_info = get_lsblk_info(mountpoint)
115+
116+
if not lsblk_info.mountpoints:
117+
return
118+
119+
debug(f'Partition {mountpoint} is currently mounted at: {[str(m) for m in lsblk_info.mountpoints]}')
120+
121+
cmd = ['umount']
122+
123+
if recursive:
124+
cmd.append('-R')
125+
126+
for path in lsblk_info.mountpoints:
127+
debug(f'Unmounting mountpoint: {path}')
128+
SysCommand(cmd + [str(path)])

archinstall/lib/luks.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pathlib import Path
66
from subprocess import CalledProcessError
77

8-
from archinstall.lib.disk.utils import get_lsblk_info
8+
from archinstall.lib.disk.utils import get_lsblk_info, umount
99

1010
from .exceptions import DiskError, SysCallError
1111
from .general import SysCommand, SysCommandWorker, generate_password, run
@@ -153,8 +153,7 @@ def unlock(self, key_file: Path | None = None) -> None:
153153
raise DiskError(f'Failed to open luks2 device: {self.luks_dev_path}')
154154

155155
def lock(self) -> None:
156-
from archinstall.lib.disk.device_handler import device_handler
157-
device_handler.umount(self.luks_dev_path)
156+
umount(self.luks_dev_path)
158157

159158
# Get crypt-information about the device by doing a reverse lookup starting with the partition path
160159
# For instance: /dev/sda
@@ -165,7 +164,7 @@ def lock(self) -> None:
165164
# Unmount the child location
166165
for mountpoint in child.mountpoints:
167166
debug(f'Unmounting {mountpoint}')
168-
device_handler.umount(mountpoint, recursive=True)
167+
umount(mountpoint, recursive=True)
169168

170169
# And close it if possible.
171170
debug(f"Closing crypt device {child.name}")

0 commit comments

Comments
 (0)