diff --git a/archinstall/lib/disk/device_handler.py b/archinstall/lib/disk/device_handler.py index be6290bb76..1918e33de4 100644 --- a/archinstall/lib/disk/device_handler.py +++ b/archinstall/lib/disk/device_handler.py @@ -207,7 +207,7 @@ def get_btrfs_info( mountpoint = Path(common_path) try: - result = SysCommand(f'btrfs subvolume list {mountpoint}').decode() + result = SysCommand(['btrfs', 'subvolume', 'list', str(mountpoint)]).decode() except SysCallError as err: debug(f'Failed to read btrfs subvolume information: {err}') return subvol_infos @@ -223,7 +223,7 @@ def get_btrfs_info( for line in result.splitlines(): # expected output format: # ID 257 gen 8 top level 5 path @home - name = Path(line.split(' ')[-1]) + name = Path(line.split(' path ', maxsplit=1)[-1]) sub_vol_mountpoint = btrfs_subvol_info.get('/' / name, None) subvol_infos.append(_BtrfsSubvolumeInfo(name, sub_vol_mountpoint)) @@ -441,17 +441,17 @@ def create_lvm_btrfs_subvolumes( subvol_path = self._TMP_BTRFS_MOUNT / sub_vol.name - SysCommand(f'btrfs subvolume create -p {subvol_path}') + SysCommand(['btrfs', 'subvolume', 'create', '-p', str(subvol_path)]) if BtrfsMountOption.nodatacow.value in mount_options: try: - SysCommand(f'chattr +C {subvol_path}') + SysCommand(['chattr', '+C', str(subvol_path)]) except SysCallError as err: raise DiskError(f'Could not set nodatacow attribute at {subvol_path}: {err}') if BtrfsMountOption.compress.value in mount_options: try: - SysCommand(f'chattr +c {subvol_path}') + SysCommand(['chattr', '+c', str(subvol_path)]) except SysCallError as err: raise DiskError(f'Could not set compress attribute at {subvol_path}: {err}') @@ -495,7 +495,7 @@ def create_btrfs_volumes( subvol_path = self._TMP_BTRFS_MOUNT / sub_vol.name - SysCommand(f'btrfs subvolume create -p {subvol_path}') + SysCommand(['btrfs', 'subvolume', 'create', '-p', str(subvol_path)]) umount(dev_path) diff --git a/archinstall/lib/disk/utils.py b/archinstall/lib/disk/utils.py index efa1f16515..6131680f84 100644 --- a/archinstall/lib/disk/utils.py +++ b/archinstall/lib/disk/utils.py @@ -168,7 +168,7 @@ def mount( debug(f'Mounting {dev_path}: {command}') try: - SysCommand(command) + SysCommand(cmd) except SysCallError as err: raise DiskError(f'Could not mount {dev_path}: {command}\n{err.message}') diff --git a/tests/test_disk_mountpoints.py b/tests/test_disk_mountpoints.py new file mode 100644 index 0000000000..b1a2ea039d --- /dev/null +++ b/tests/test_disk_mountpoints.py @@ -0,0 +1,69 @@ +from pathlib import Path +from unittest.mock import MagicMock, patch + +from archinstall.lib.disk.device_handler import DeviceHandler +from archinstall.lib.disk.utils import mount +from archinstall.lib.models.device import LsblkInfo + + +def _make_lsblk_info(mountpoint: Path | None, mountpoints: list[Path], fsroots: list[Path]) -> LsblkInfo: + return LsblkInfo.model_validate( + { + 'name': 'sda1', + 'path': '/dev/sda1', + 'pkname': 'sda', + 'log-sec': 512, + 'size': 1024 * 1024, + 'pttype': 'gpt', + 'ptuuid': None, + 'rota': False, + 'tran': 'sata', + 'partn': 1, + 'partuuid': None, + 'parttype': None, + 'uuid': None, + 'fstype': 'btrfs', + 'fsver': None, + 'fsavail': None, + 'fsuse%': None, + 'type': 'part', + 'mountpoint': mountpoint, + 'mountpoints': mountpoints, + 'fsroots': fsroots, + } + ) + + +def test_get_btrfs_info_with_space_in_mountpoint() -> None: + mountpoint = Path('/mnt/Cleartext Storage') + lsblk_info = _make_lsblk_info( + mountpoint=mountpoint, + mountpoints=[mountpoint], + fsroots=[Path('/@data')], + ) + + mock_cmd = MagicMock() + mock_cmd.decode.return_value = 'ID 256 gen 16 top level 5 path @data\n' + + handler = DeviceHandler.__new__(DeviceHandler) + + with patch('archinstall.lib.disk.device_handler.SysCommand', return_value=mock_cmd) as sys_cmd: + subvols = handler.get_btrfs_info('/dev/sda1', lsblk_info=lsblk_info) + + sys_cmd.assert_called_once_with(['btrfs', 'subvolume', 'list', '/mnt/Cleartext Storage']) + assert len(subvols) == 1 + assert subvols[0].name == Path('@data') + assert subvols[0].mountpoint == mountpoint + + +def test_mount_with_space_in_target_mountpoint(tmp_path: Path) -> None: + target = tmp_path / 'Cleartext Storage' + lsblk_info = _make_lsblk_info(mountpoint=None, mountpoints=[], fsroots=[]) + + with ( + patch('archinstall.lib.disk.utils.get_lsblk_info', return_value=lsblk_info), + patch('archinstall.lib.disk.utils.SysCommand') as sys_cmd, + ): + mount('/dev/sda1', target, options=['subvol=@']) + + sys_cmd.assert_called_once_with(['mount', '-o', 'subvol=@', '/dev/sda1', str(target)])