Break an import cycle between lib/luks and lib/disk/device_handler (#3438)

This commit is contained in:
correctmost 2025-05-05 03:04:16 -04:00 committed by GitHub
parent 4ed6d0da9b
commit 781760a157
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 25 deletions

View File

@ -45,6 +45,7 @@ from .utils import (
find_lsblk_info,
get_all_lsblk_info,
get_lsblk_info,
umount,
)
@ -257,7 +258,7 @@ class DeviceHandler:
subvol_infos.append(_BtrfsSubvolumeInfo(name, sub_vol_mountpoint))
if not lsblk_info.mountpoint:
self.umount(dev_path)
umount(dev_path)
return subvol_infos
@ -635,7 +636,7 @@ class DeviceHandler:
except SysCallError as err:
raise DiskError(f'Could not set compress attribute at {subvol_path}: {err}')
self.umount(path)
umount(path)
def create_btrfs_volumes(
self,
@ -677,7 +678,7 @@ class DeviceHandler:
SysCommand(f"btrfs subvolume create -p {subvol_path}")
self.umount(dev_path)
umount(dev_path)
if luks_handler is not None and luks_handler.mapper_dev is not None:
luks_handler.lock()
@ -710,7 +711,7 @@ class DeviceHandler:
if partition.fs_type == FilesystemType.Crypto_luks:
Luks2(partition.path).lock()
else:
self.umount(partition.path, recursive=True)
umount(partition.path, recursive=True)
def partition(
self,
@ -790,23 +791,6 @@ class DeviceHandler:
except SysCallError as err:
raise DiskError(f'Could not mount {dev_path}: {command}\n{err.message}')
def umount(self, mountpoint: Path, recursive: bool = False) -> None:
lsblk_info = get_lsblk_info(mountpoint)
if not lsblk_info.mountpoints:
return
debug(f'Partition {mountpoint} is currently mounted at: {[str(m) for m in lsblk_info.mountpoints]}')
cmd = ['umount']
if recursive:
cmd.append('-R')
for path in lsblk_info.mountpoints:
debug(f'Unmounting mountpoint: {path}')
SysCommand(cmd + [str(path)])
def detect_pre_mounted_mods(self, base_mountpoint: Path) -> list[DeviceModification]:
part_mods: dict[Path, list[PartitionModification]] = {}

View File

@ -108,3 +108,21 @@ def disk_layouts() -> str:
return ''
return lsblk_output.model_dump_json(indent=4)
def umount(mountpoint: Path, recursive: bool = False) -> None:
lsblk_info = get_lsblk_info(mountpoint)
if not lsblk_info.mountpoints:
return
debug(f'Partition {mountpoint} is currently mounted at: {[str(m) for m in lsblk_info.mountpoints]}')
cmd = ['umount']
if recursive:
cmd.append('-R')
for path in lsblk_info.mountpoints:
debug(f'Unmounting mountpoint: {path}')
SysCommand(cmd + [str(path)])

View File

@ -5,7 +5,7 @@ from dataclasses import dataclass
from pathlib import Path
from subprocess import CalledProcessError
from archinstall.lib.disk.utils import get_lsblk_info
from archinstall.lib.disk.utils import get_lsblk_info, umount
from .exceptions import DiskError, SysCallError
from .general import SysCommand, SysCommandWorker, generate_password, run
@ -153,8 +153,7 @@ class Luks2:
raise DiskError(f'Failed to open luks2 device: {self.luks_dev_path}')
def lock(self) -> None:
from archinstall.lib.disk.device_handler import device_handler
device_handler.umount(self.luks_dev_path)
umount(self.luks_dev_path)
# Get crypt-information about the device by doing a reverse lookup starting with the partition path
# For instance: /dev/sda
@ -165,7 +164,7 @@ class Luks2:
# Unmount the child location
for mountpoint in child.mountpoints:
debug(f'Unmounting {mountpoint}')
device_handler.umount(mountpoint, recursive=True)
umount(mountpoint, recursive=True)
# And close it if possible.
debug(f"Closing crypt device {child.name}")