Files
romm/backend/handler/filesystem/retroarch_sync_handler.py
Georges-Antoine Assi 0c7633f4bb refactor(sync): apply simplify pass to the RetroArch manifest perf work
- Key PSP member hashes on the bundle's content hash, computed once in a
  thread, cached via the shared batch helper, and guarded only on write
- Build only the requested tree for a PROPFIND listing
- Walk blobs with iter_files, share the bundle limit check and reader
- Drop the derivable ManifestAsset.parent_path and the closure factories

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 16:34:41 -04:00

57 lines
1.6 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 SYNC_RETROARCH_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=SYNC_RETROARCH_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)