mirror of
https://github.com/rommapp/romm.git
synced 2026-12-04 21:02:21 +01:00
feat(fs): hardlink import/export assets when possible, harden sync init
Importer (gamelist/launchbox file:// flows) and exporters (gamelist.xml, metadata.pegasus.txt local exports) now hardlink media assets when source and destination share a filesystem, falling back transparently to a copy on EXDEV / EPERM / EOPNOTSUPP / EMLINK / EACCES (cross-device, FAT32, exFAT, network mounts, etc.). Saves disk space and is effectively instantaneous on large files (videos, manuals, miximages). Covers keep a real copy (allow_link=False) because _store_cover resizes the small cover in place via PIL.Image.save, which would truncate the shared inode and corrupt the user's source image. Also makes FSSyncHandler tolerate a missing/unwritable /romm/sync at startup: an OSError from mkdir now logs a warning instead of crashing the whole app at module-import time. Sync calls still fail at use time if the mount remains broken — the right place to surface the error. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
"""Tests for filesystem sync handler."""
|
||||
|
||||
import errno
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -133,3 +135,21 @@ class TestFSSyncHandler:
|
||||
def test_remove_incoming_file_nonexistent(self, handler: FSSyncHandler):
|
||||
# Should not raise for nonexistent files
|
||||
handler.remove_incoming_file("/nonexistent/path/file.sav")
|
||||
|
||||
|
||||
class TestFSSyncHandlerStartup:
|
||||
"""Sync is an optional feature: if /romm/sync isn't writable (bad mount,
|
||||
wrong ownership), the app must still boot. Failures should surface when
|
||||
sync is actually used, not at module-import time."""
|
||||
|
||||
def test_init_does_not_raise_when_base_path_unwritable(self):
|
||||
"""Regression test for the PermissionError on /romm/sync at boot.
|
||||
FSSyncHandler must construct successfully even when mkdir fails."""
|
||||
with patch.object(
|
||||
Path, "mkdir", side_effect=PermissionError(errno.EACCES, "denied")
|
||||
):
|
||||
handler = FSSyncHandler()
|
||||
|
||||
assert handler is not None
|
||||
# base_path is set even though the directory wasn't created.
|
||||
assert isinstance(handler.base_path, Path)
|
||||
|
||||
Reference in New Issue
Block a user