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

+3 -14
View File
@@ -61,7 +61,7 @@ from .fbneo_parser import zip_name
from .clex import DriverSourceError, blank_comments, call_args, call_span
from .listxml import Opener, attrs, iter_elements, open_listxml, rom_members
from model.mamerelease import mame_tag
from .romset_dat_importer import MAME_LISTXML_URL, _api_json, fetch_pack
from .romset_dat_importer import MAME_LISTXML_URL, _api_json, cached_pack, fetch_pack
SCHEMA_VERSION = 1
DEFAULT_OUTPUT = Path("games") / "arcade"
@@ -953,12 +953,7 @@ def import_profile(
openers: list[Opener]
if kind == "listxml":
tag = mame_tag(str(data["core_version"]))
if offline:
pack = cache_dir / f"{tag}lx.zip"
if not pack.is_file():
raise FileNotFoundError(f"{pack} is not cached")
else:
pack, _ = fetch_pack("mame", tag, cache_dir)
pack, _ = (cached_pack if offline else fetch_pack)("mame", tag, cache_dir)
source = {
"release": f"mamedev/mame {tag}",
"url": MAME_LISTXML_URL.format(tag=tag),
@@ -966,13 +961,7 @@ def import_profile(
}
index = build_index(read_sets([lambda: open_listxml(pack)]), spec["marker"])
elif kind == "fbneo":
if offline:
folder = cache_dir / "fbneo-dats"
blobs = {p.name: git_blob_sha(p.read_bytes()) for p in sorted(folder.glob("*.dat"))}
if not blobs:
raise FileNotFoundError(f"{folder} is not cached")
else:
folder, blobs = fetch_pack("fbneo", commit, cache_dir)
folder, blobs = (cached_pack if offline else fetch_pack)("fbneo", commit, cache_dir)
slug = _repo_slug(source_url)
listing, listing_sha = (
_cached_repo_file(slug, commit, FBNEO_DRIVERLIST, cache_dir)
+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.