Files
romm/backend/handler/filesystem/retroarch_sync_handler.py
Georges-Antoine Assi 3f13d1e752 fix(sync): store RetroArch Cloud Sync blobs under the assets volume (#5155)
The config/, thumbnails/ and system/ blobs lived at /romm/retroarch_sync,
which no documented mount covers, so they sat in the image's anonymous
/romm volume and were lost on `compose down`/`up`, `-V`, or a
docker rm/run upgrade. RetroArch can then treat the missing files as
deleted on the server and drop its local copies.

They now live at assets/users/<user>/retroarch/<category>/, beside the
user's saves and states. The old path never shipped in a release, so
no data migration is needed.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 19:31:21 -04:00

57 lines
1.5 KiB
Python

"""Opaque per-user storage for the Cloud Sync categories no ROM owns: config/,
thumbnails/ and system/."""
import asyncio
import stat
from dataclasses import dataclass
from pathlib import Path
from config import ASSETS_BASE_PATH
from utils.filesystem import iter_files
from .base_handler import FSHandler
@dataclass(frozen=True)
class BlobFile:
"""A file under a blob prefix, with the stat fields its hash cache key uses."""
relative_path: str
size: int
mtime: float
def _walk_files(root: Path) -> list[BlobFile]:
"""Every file under `root`, without descending into symlinked directories."""
files: list[BlobFile] = []
for directory, name in iter_files(str(root), recursive=True):
path = directory / name
try:
file_stat = path.stat()
except OSError:
continue
if stat.S_ISREG(file_stat.st_mode):
files.append(
BlobFile(
path.relative_to(root).as_posix(),
file_stat.st_size,
file_stat.st_mtime,
)
)
return files
class FSRetroArchSyncHandler(FSHandler):
def __init__(self) -> None:
super().__init__(base_path=ASSETS_BASE_PATH)
async def list_blob_files(self, prefix: str) -> list[BlobFile]:
"""Every file under `prefix` (relative to the blob root), relative to `prefix` itself."""
try:
root = self.validate_path(prefix)
except ValueError:
return []
return await asyncio.to_thread(_walk_files, root)