Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions archinstall/lib/disk/device_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))

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

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

Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/disk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')

Expand Down
69 changes: 69 additions & 0 deletions tests/test_disk_mountpoints.py
Original file line number Diff line number Diff line change
@@ -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)])