mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 05:39:57 -05:00
Disks: allow persisting the primary mount from the UI; clean NTFS before mounting.
The Disks page treated /media/wrolpi as fully protected, so a manually-mounted primary drive could not be persisted from the UI — and the Persist toggle would have been wrong anyway: it wrote fstab.yaml, which the wrolpi-mounts reconciler refuses to apply for the primary mount (RESERVED_MOUNT_POINTS). Route Persist for the primary mount to the host's /etc/fstab (as onboarding does), report its entry in the fstab list endpoint, and enable the toggle in both UIs while keeping Unmount blocked. Mounts outside /media (e.g. /boot/efi, which showed an Unmount button) are now entirely untouchable System mounts. Also: - Run `ntfsfix -d` before mounting ntfs/ntfs3 volumes so the Windows dirty flag (Fast Startup, unclean unplug) cannot block mounting; non-fatal and a no-op on clean volumes. - Add uid/gid fstab options for ntfs/ntfs3, matching mount_drive(). - Log reconcile diagnostics (desired/already-mounted/skipped with reasons) so an idle wrolpi-mounts run explains itself in the journal. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
85bd5619fa
commit
c25902b92a
11 changed files with 251 additions and 18 deletions
|
|
@ -268,6 +268,45 @@ class TestMountDrive:
|
|||
assert result["success"] is False
|
||||
assert "mount failed" in result["error"]
|
||||
|
||||
def test_ntfs_mount_runs_ntfsfix_first(self):
|
||||
"""NTFS mounts run ntfsfix -d before mount to clear the Windows dirty flag."""
|
||||
with mock.patch("controller.lib.disks.is_docker_mode", return_value=False), \
|
||||
mock.patch("controller.lib.disks.get_wrolpi_uid_gid", return_value=(1001, 1001)), \
|
||||
mock.patch("pathlib.Path.mkdir"), \
|
||||
mock.patch("subprocess.run") as mock_run:
|
||||
mock_run.return_value = mock.Mock(returncode=0, stdout="", stderr="")
|
||||
result = mount_drive("/dev/sdb2", "/media/test", fstype="ntfs")
|
||||
assert result["success"] is True
|
||||
commands = [c[0][0] for c in mock_run.call_args_list]
|
||||
assert commands[0][:2] == ["ntfsfix", "-d"]
|
||||
assert "/dev/sdb2" in commands[0]
|
||||
assert commands[1][0] == "mount"
|
||||
|
||||
def test_ntfsfix_failure_does_not_block_mount(self):
|
||||
"""A failed ntfsfix is logged but the mount is still attempted."""
|
||||
with mock.patch("controller.lib.disks.is_docker_mode", return_value=False), \
|
||||
mock.patch("controller.lib.disks.get_wrolpi_uid_gid", return_value=(1001, 1001)), \
|
||||
mock.patch("pathlib.Path.mkdir"), \
|
||||
mock.patch("subprocess.run") as mock_run:
|
||||
mock_run.side_effect = [
|
||||
mock.Mock(returncode=1, stdout="", stderr="ntfsfix failed"), # ntfsfix
|
||||
mock.Mock(returncode=0, stdout="", stderr=""), # mount
|
||||
]
|
||||
result = mount_drive("/dev/sdb2", "/media/test", fstype="ntfs")
|
||||
assert result["success"] is True
|
||||
|
||||
def test_ext4_mount_does_not_run_ntfsfix(self):
|
||||
"""Non-NTFS mounts must not invoke ntfsfix."""
|
||||
with mock.patch("controller.lib.disks.is_docker_mode", return_value=False), \
|
||||
mock.patch("pathlib.Path.mkdir"), \
|
||||
mock.patch("subprocess.run") as mock_run:
|
||||
mock_run.return_value = mock.Mock(returncode=0, stdout="", stderr="")
|
||||
result = mount_drive("/dev/sda1", "/media/test", fstype="ext4")
|
||||
assert result["success"] is True
|
||||
commands = [c[0][0] for c in mock_run.call_args_list]
|
||||
assert len(commands) == 1
|
||||
assert commands[0][0] == "mount"
|
||||
|
||||
@pytest.mark.parametrize("fstype,expect_uid_gid", [
|
||||
("exfat", True),
|
||||
("vfat", True), # FAT32
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue