fix: key the fbneo dat cache by commit

fetch_pack refilled one fbneo-dats folder for whatever revision was
asked, and the offline arcade import rebuilt its paths by hand: a parent
map labelled with the profile's pin could be read from another commit's
DATs. The folder is now fbneo-dats/<sha>, and cached_pack() next to
fetch_pack is the offline read, raising NotCached.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 19:50:10 +01:00
1 parent bc48d4028a
commit 398782a5cd
3 files changed
+54 -17

No files matched your search

+34 -2
View File
@@ -40,6 +40,7 @@ from datetime import datetime, timezone
from pathlib import Path
from typing import IO
from core.hashing import git_blob_sha
from core.ziptools import is_archive_path, zip_members
from model.registry import list_registered_platforms
from model.profiles import load_emulator_profiles
@@ -419,6 +420,20 @@ def fetch_tag(source: str, requested: str) -> str:
return requested
class NotCached(FileNotFoundError):
"""The cache holds no pack for the revision asked."""
def _listxml_path(tag: str, cache_dir: Path) -> Path:
return cache_dir / f"{tag}lx.zip"
def _fbneo_folder(commit: str, cache_dir: Path) -> Path:
# One folder per commit: a folder refilled for whatever revision was
# last asked gave an offline read the DATs of another pin.
return cache_dir / "fbneo-dats" / commit
def fetch_pack(
source: str, tag: str, cache_dir: Path
) -> tuple[Path, dict[str, str]]:
@@ -431,7 +446,7 @@ def fetch_pack(
FBNeo, whose files change under a constant header version.
"""
if source == "mame":
listxml = cache_dir / f"{tag}lx.zip"
listxml = _listxml_path(tag, cache_dir)
download(MAME_LISTXML_URL.format(tag=tag), listxml, skip_existing=True)
return listxml, {}
@@ -442,7 +457,7 @@ def fetch_pack(
listing = _api_json(f"{FBNEO_API}/contents/dats?ref={sha}")
if not isinstance(listing, list):
raise BlobMismatchError(f"libretro/FBNeo lists no dats at {sha}")
target = cache_dir / "fbneo-dats"
target = _fbneo_folder(sha, cache_dir)
target.mkdir(parents=True, exist_ok=True)
blobs: dict[str, str] = {}
for item in listing:
@@ -460,6 +475,23 @@ def fetch_pack(
return target, blobs
def cached_pack(
source: str, revision: str, cache_dir: Path
) -> tuple[Path, dict[str, str]]:
"""What fetch_pack wrote for *revision* (a MAME tag, a full FBNeo commit),
read offline. The FBNeo blobs are recomputed from the bytes."""
if source == "mame":
listxml = _listxml_path(revision, cache_dir)
if not listxml.is_file():
raise NotCached(f"{listxml} is not cached")
return listxml, {}
folder = _fbneo_folder(revision, cache_dir)
blobs = {p.name: git_blob_sha(p.read_bytes()) for p in sorted(folder.glob("*.dat"))}
if not blobs:
raise NotCached(f"{folder} is not cached")
return folder, blobs
def _is_listxml(pack: Path) -> bool:
"""Whether *pack* holds a MAME -listxml document rather than a DAT.