Testing the custom library structure against a live library turned up four
defects, all of them a path being reduced to a bare file name.
Both exporters wrote a rom's `fs_name` alone, so every game a template nests
was exported as if it sat in the platform folder: ES-DE and Pegasus could not
find any of them. They now write the rom's path relative to the platform
folder, the folder the metadata files themselves live in, and copy exported
media into the matching subfolder so two identically named roms keep their own
artwork.
Merging into an existing gamelist.xml / metadata.pegasus.txt keyed entries by
file name too, so identically named roms in different folders both merged into
the first entry and produced duplicates. Entries are now keyed by path, with a
Pegasus block matched by the folder its listed files sit in.
Reading a gamelist.xml had the same collision: two roms sharing a file name
both took the metadata of whichever entry was parsed last. A rom's own path now
wins, and a bare file name stays a fallback key for the tools that write those,
dropped when two entries share it.
Default discovery surfaced hidden folders as multi-file games, unlike
structured discovery which skips them. exclude_multi_roms now owns that rule
for both.
Also validate `exclude`'s exclusion_type: an unknown value reached
`Config.__getattribute__` and returned a 500 rather than a 422.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Pegasus logo and marquee both land in ES-DE's marquees folder. With the
same extension the second copy was skipped as already present, and the
metadata pointed both keys at the first file. A destination already
claimed by another source now gets the asset key appended to its name.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019Dye15Zspts7hBruKYsPuT
Exporting for both ES-DE and Pegasus after a scan wrote every media file
twice: once into the ES-DE per-type folders beside the ROMs, and once into
a parallel assets/ tree with Pegasus's own folder names. Pegasus resolves
media from the paths written in metadata.pegasus.txt, so it has no need
for a layout of its own. The exporter now copies into the same folders
the gamelist export uses and references them from the metadata file,
leaving one copy of each file and no assets/ directory.
Existing assets/ trees are left in place; the scan already excludes them.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019Dye15Zspts7hBruKYsPuT
Pegasus reads both `asset.` and `assets.` prefixes and several spellings
of each asset name (boxFront, boxart2D, videos, wheel, ...). Left
distinct, an old asset line survived beside RomM's freshly emitted one
and Pegasus loaded both.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Pegasus also reads sortname, sort_name and sort-name as the sort title.
Left distinct, an old spelling survived after RomM's sort-by and Pegasus
applied the stale value.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Decode both files with utf-8-sig so a BOM from a Windows editor no longer
blocks the gamelist parse or hides the Pegasus collection header. Parse
gamelist.xml with comments and processing instructions retained so they
are written back. Keep a second <game> whose path shares a filename with
an earlier one as an unmanaged entry instead of overwriting it. Index a
Pegasus block by the top folder of each listed file as well, so a block
listing the discs of a game folder merges into RomM's multi-file entry.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Both exporters rebuilt their file from the database on every run, so a
scan with `scan.gamelist.export: true` threw away everything the frontend
or the user had written into it: favorites, play counts, per-game
emulator and core overrides, hashes, `<folder>` entries, ES-DE's
`<alternativeEmulator>` block, and Pegasus launch commands.
The exporters now read the existing file first and merge into it. For a
ROM RomM knows, the tags and keys RomM emits replace the old ones and
everything else is carried over. Entries with no matching ROM, folders,
scraper provider blocks and later Pegasus collections are written back
untouched. A file that cannot be parsed or decoded is left alone and the
export for that platform fails instead of replacing it.
Fixes#4158
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XjH6MYLVFVoY92JdBFgKXw
Stamping PPMd coupled the tests to the stdlib's codec list; a Python that
learns PPMd would have made them pass through zipfile and stop exercising
the 7zz dispatch. 0xFFFF is an id the zip spec never assigned. The
integration test keeps a genuine PPMd archive.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The unit tests stamp PPMd onto a stored zip and mock 7zz, which proves the
dispatch but not that 7zz can read such an archive. This adds an
integration test that has 7zz write a genuine PPMd zip next to a stored
.cue, checks zipfile refuses it, and compares the member hashes the reader
yields against hashes of the source files. CI installs 7zip so the test
runs there; it skips where 7zz is absent.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Python's zipfile only decodes Stored, Deflate, bzip2, LZMA and (via the
inflate64 patch) Deflate64. A zip written with PPMd, zstd, xz, AES or the
legacy Implode family raised NotImplementedError, which the scanner turned
into "hash the container instead". Those hashes match no ROM database, so
the ROM could never be verified against Hasheous.
The zip reader now opens each eligible entry once up front. If zipfile has
no decoder for any of them, the whole archive is read through the existing
7zz-backed reader, which handles every method the zip spec allows. Falling
back for the whole archive rather than per member keeps a stored .cue next
to a PPMd .bin from being streamed twice into the composite hash. Excluded
members do not influence the decision.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Cut the prose that narrates the function bodies and the Args blocks that
restate the signatures, keeping only the non-obvious contract: when
resolve_fs_slug returns None.
Rename test_reverse_map_is_unambiguous to say what it asserts, that the
reverse map agrees with the alias table.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Batocera, RetroBat and ES-DE all ship an `easyrpg` folder for RPG Maker
2000/2003 games, but RomM had no platform for them, so the folder fell
through as an unmatched platform that matched no metadata.
Add UniversalPlatformSlug.RPG_MAKER and wire it to the two providers that
carry the platform: ScreenScraper (system 231, "EasyRPG") for metadata and
libretro (system "RPG Maker") for thumbnails. IGDB, MobyGames and TheGamesDB
have no RPG Maker platform, so they stay unmapped, the same way DOOM is
wired.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Fold the folder name resolution into one home and make it case-insensitive
end to end.
Config folder names are lowercased as the config is parsed, so bindings,
versions and the built-in alias table are all matched the same way. A SNES/
folder now resolves, and a binding written GameCube: matches a gamecube/
folder.
Add resolve_fs_slug(), the inverse used to recover a renamed folder, which
replaces the two swapped dicts in scan_platform. Only slugs reached by
exactly one folder name are reversible, so recovery never guesses between
amiga500, amiga600 and amiga1200.
Validate system.platforms and system.versions through one helper that
rejects empty and non-string values, and treat a null block as empty rather
than exiting.
Restore the atari800 override in the example configs: its folder name is
itself a RomM slug, so it can never be an alias. A new test derives the
needed overrides from the alias table to keep the examples honest.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Fold the exporter's folder map and the importer's ESDE_MEDIA_MAP into a
single GAMELIST_MEDIA_DIRS, so writing, reading and skipping a media type
is one edit. This also picks up thumbnails/, which the scan exclusions were
missing, and drops the hand-appended "images" literal.
Serve the multi-file defaults pre-unioned as DEFAULT_EXCLUDED_MULTI_DIRS so
neither UI has to re-join two lists; v1 was still mapping EXCLUDED_MULTI_FILES
to DEFAULT_EXCLUDED_DIRS and rendering the media dirs as deletable.
Collapse the per-tag asset loop and the bespoke <mix> block into one table
keyed by tag, and skip fnmatch for the exclusion patterns that hold no glob
characters, now that the multi-file list is more than twice as long.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Master moved UniversalPlatformSlug to utils/platform_slugs.py so that naming
a platform no longer imports the metadata stack. The alias table and its
test now import the enum from there, and utils/platforms.py keeps both the
new leaf import and the resolver import.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Frontend system folders such as gamecube, megadrive or n3ds only became
RomM platforms after the user copied a 100+ line system.platforms map into
config.yml. A built-in alias table now covers the folder names those
frontends use, seeded from the two example configs and cross-checked
against the upstream system lists.
Resolution order is unchanged for existing users: config bindings and
versions win, a folder name that already is a slug keeps matching itself,
and only then is the alias table consulted. The two call sites that
resolved folder names by hand share one resolver.
The example configs shrink to genuine overrides. The Batocera example
also mapped odyssey2 to the original Odyssey; the alias points at
Odyssey 2.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ES-DE ignores media paths inside gamelist.xml and only looks in
<MediaDirectory>/<system>/<mediatype>/<rom>.<ext>. The exporter wrote to
<platform>/assets/<mediatype>/, which that scheme cannot reach, and used
"boxes" and "physical" where ES-DE expects "3dboxes" and "physicalmedia".
Media now lands directly in the platform directory under ES-DE's folder
names, matching what the gamelist importer already reads, so media scraped
by ES-DE is reused instead of duplicated.
The folder map moves to config_manager so the default scan exclusions are
derived from it and the exported folders are never picked up as multi-file
ROMs. RetroBat's "images" folder is excluded for the same reason.
RetroBat and Batocera read paths from gamelist.xml but under their own tag
names, so <cartridge>, <titleshot> and <mix> are written alongside the
ES-DE tags.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Cut the docstring paragraphs down to the one fact each reader cannot get
from the code, name the readability test after the helper it exercises, and
give the flock stand-in and the zip factory real signatures.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
get_cached_zip already stats the archive to decide whether it exists, so
hand that stat back instead of making head_rom_content take another one for
Content-Length. A HEAD on a cached multi-file ROM now costs one stat.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Give 0o644 a single home in utils/filesystem as SERVED_FILE_MODE, used by
both the ZIP cache and FSHandler._atomic_write. Collapse the mode repair to
one call site behind a single stat per cache hit, close the temp descriptor
unconditionally, and log the build where the namespace is already in scope.
Deduplicate the test fixtures and drive the concurrency test with a barrier
on flock instead of a sleep, so the race is guaranteed rather than timed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Trim the constant comments down to the non-obvious facts, and relax the two
exact-TTL assertions that would flake if a second elapsed mid-test.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Two review findings on the heartbeat rate limit.
The client IP comes from a forwarded header the caller controls, since the
container runs uvicorn with --forwarded-allow-ips="*", so rotating that header
defeated the per-IP cap outright; a distributed flood has no single IP to key
on either. Caching each source's result for the length of the window bounds
outbound provider probes at one per source, whatever the inbound rate. The
per-IP cap stays as the cheap first gate.
The window's INCR and EXPIRE were separate round trips, so a call interrupted
between them left a counter with no TTL that later calls never repaired,
locking that key out for good. Both now run in one transaction, with EXPIRE NX
so a live window is never extended and a counter can never lack a TTL.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Reverts the FileRow hash-chip loop. It was left over from the per-file
version chip that no longer exists, so it is unrelated to title ids.
Cuts the comments that restate the code or defend an obvious choice, and
the `Args:` block on `get_matching_missing_rom` that repeated its own
parameter names. The CNMT content-type rationale now lives only on
`CONTENT_TYPE_CATEGORIES`.
Tests exercise the production path: the title id regex is checked with
`fullmatch`, the way the caller uses it, and `test_identity` builds its
auth header the way every other endpoint test does.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Rename embedding now goes through the handler's own rename primitive
(`rename_fs_rom`), so it inherits the library-root path validation and
per-path locking every other write in that class gets, and builds the new
name with the repo's multi-part extension helpers.
Extraction no longer reads files it can never parse: archives, manuals,
soundtracks and screenshots are skipped, and on non-Switch platforms it
stops after the first result, since only Switch looks at a per-file
content type.
Also collapses the two rom-level branches (dropping a closure), gives the
Switch family one home in RomM's own terms instead of deriving it from
sigil's slug string, logs an unrecognized save target layout instead of
dropping it silently, deletes the `ScannedFSRomValues` mirror of `FSRom`,
drops a dead `rom.version` locale key, and slims the sigil Docker builds
to one layer with a filtered clone.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Upstream took 0113, so the sigil migration rechains onto
0113_roms_locked_fields as 0114. The sigil build stage keeps its place
ahead of the emulator stage, which upstream renamed for js-dos.
What a base-game id looks like, how to recover one from an update or DLC
id, and how a content type maps to a category are facts about the
platform, not about scanning a filesystem, and they sat in the middle of
a handler that is nine hundred lines of other concerns. The rename that
embeds an id stays with the filesystem code that owns file operations
and imports the patterns it needs.
The saves handler carried two ROM filters that ANDed together, and the states
handler had only the singular one, so the same "which ROMs" question had three
answers across two sibling handlers. Collapse both onto rom_ids: a single-ROM
lookup is just a one-element scope, which is what the three internal callers in
the saves endpoint now pass.
That leaves the routes to fold their own public rom_id param into the scope.
Rather than write the fold twice, narrow_rom_id_scope joins utils/validation
beside RomIdScope, keeping the documented "combined with rom_id" semantics: both
filters still apply together, so the effective scope is their intersection.
GET /api/states gains the rom_ids param GET /api/saves got in #4304, declared
with the same shared RomIdScope, so a client syncing a known set of ROMs can
discover states the same way it discovers saves, under the same cap and the same
422 on a bad scope.
One behaviour shift falls out of the handler's old falsy check: rom_id=0 used to
be ignored and return the whole library, and now scopes to nothing, which is
what RomIdScope's positive-ID rule says a zero means.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The dev-mode in-memory ZIP branch of `get_rom_content` never called the
`zipfile._get_compressor` shim, so `zipfile-inflate64`'s one-arg override
raised a `TypeError` inside `_ZipWriteFile.__init__`. That leaves
`ZipFile._writing` stuck `True`, and `__exit__` masks the real error with
"Can't close the ZIP file while there is an open writing handle on it",
returning a 500 for any multi-file ROM.
The shim is now shared with the endpoint, so it drops its underscore.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The discovery script imported build_search_payload from hltb_handler, which
pulls in handler/metadata/__init__ and so instantiates every metadata handler,
opens Redis and writes a config file at import time. That import side effect is
why the workflow needed a dummy ROMM_BASE_PATH.
The script also hand-forked the rest of the protocol (base headers, the /init
mint, the session headers and the honeypot body merge), so it validated a
candidate route against a copy of what the handler sends rather than against
the real thing.
Move the contract into utils/hltb_search.py, a leaf module both sides import,
and drop ROMM_BASE_PATH from CI.
Pace failed session mints too: _ensure_session retried on every lookup, so a
down or IP-blocking HLTB cost each ROM in a scan its own rate-limited /init
round trip.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Metadata providers (ScreenScraper, RetroAchievements, LaunchBox,
Flashpoint, gamelist, IGDB) distinguish the publisher from the developer
of a game, but RomM amalgamated both into a single `companies` list at
ingestion, so the distinction was unrecoverable. This adds `publishers`
and `developers` as new, refined fields end to end while keeping
`companies` (the merged union) working exactly as before.
Backend:
- Handlers now emit publishers/developers alongside the unchanged
companies list; IGDB requests the involved_companies developer/
publisher flags to split by role.
- Migration 0112 adds generated_publishers/generated_developers columns
on roms, projects them through the roms_metadata view, mirrors them
into roms_facets, and adds publisher/developer virtual-collection
types (triggers/functions rebuilt for MariaDB/MySQL + PostgreSQL).
- Filters, facets, endpoints, smart collections and the gamelist/pegasus
exporters all carry the new fields; exporters prefer the explicit
split and fall back to the companies heuristic for un-rescanned ROMs.
Frontend (v2):
- Shared filter store + API service, gallery filter drawer, URL
persistence, game detail display (Developers/Publishers with a
Companies fallback), edit dialog, smart-collection criteria, and a
publisher/developer "group virtual collections by" option.
- Also relabels the confusing "company"->"Developer" group-by option
to "Company" now that a proper Developer option exists.
Fixes#3518
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Minting a session only proved a candidate route was session-backed, not that it
answers the search the handler sends. A future session-minting route sorting
ahead of the game-search route would have been published on that evidence alone,
leaving installs without completion metadata until the fixture was corrected.
Discovery now completes the real exchange: it mints a session, POSTs a search
with it, and requires the HLTB game shape that search_games() reads back. The
payload is no longer duplicated for the check, it moves to build_search_payload()
so the handler and discovery send the same body.
Also fixes the workflow being unable to run this script at all. It imports the
backend config, which raises unless ROMM_AUTH_SECRET_KEY is set, and the workflow
set no environment, so every run (including the manual dispatches) died at import
before reaching any HLTB logic. That is why the fixture drifted from May despite
the workflow existing.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
HLTB lookups have returned nothing since HLTB rotated their search endpoint.
The published fixture still pointed at /api/bleed, which now 404s on both GET
and POST, and the handler fetches that fixture from master at every startup, so
every install was affected regardless of image version. The live endpoint is
/api/search/site, with the session mint at /api/search/site/init, which the
handler already derives as f"{search_url}/init".
The automation meant to keep the fixture current could not have fixed this on
its own. It only ran on workflow_dispatch, so it never ran unprompted, and HLTB
has since migrated to Turbopack: the homepage no longer serves a pages-router
_app chunk, so both app-chunk regexes matched nothing. The endpoint is also a
plain literal in the bundle now rather than the .concat() obfuscation the token
regex expected.
Discovery now reads _buildManifest.js, where Next.js lists every route as a
plain literal, and selects the route that has an /init sibling, the same pairing
HLTBHandler assumes. That rule uniquely picks /api/search/site out of the 90 API
routes in the manifest, and rejects near misses such as /api/forum/search. Each
candidate then has to mint a real session before the fixture is written, so a
dead URL cannot be published again.
A failed startup was also permanent and silent: _request() returned early
whenever there was no session and nothing re-minted one, so a container that
lost the mint at boot served no HLTB metadata for its whole lifetime with no
error after the startup warning. Failures are now logged, and lookups mint
lazily behind a lock so a scan's concurrent lookups do not each hit /init.
Fixes#4285
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Physical games encoded file-lessness as is_physical=True with
missing_from_fs=False, while every consumer asked the same question through
missing_from_fs alone. Each of those consumers was therefore wrong for a
physical game, and each would have needed its own is_physical rider.
Add Rom.has_file_on_disk, covering both reasons a rom has no file, expose it
on RomSchema, and route the file-dependent surfaces through it:
- The ES-DE and Pegasus exporters no longer emit entries whose path points at
the .physical sentinel folder.
- The device feeds gain a single _servable_roms() seam, so all three entry
points that enumerate roms drop the ones with no file rather than minting
download URLs for them.
- GET /roms/{id}/content answers 404 with a reason instead of falling through
to the generic "no files found".
- v2 gates Play, Download, copy-link and the QR share on the flag, in
useCanPlay and useGameActions rather than at each of the surfaces.
The is_physical exclusions in mark_missing_roms stay: they are what maintains
the invariant that a physical game is never flagged missing, and the one in
the missing filter keeps a stray flag away from the cleanup task that
hard-deletes.
Also translate the physical-game and barcode strings, which had been copied
into eleven locales as English.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Truncated tars surface while listing, since `getmembers()` walks the whole
archive before any member is streamed, so the streaming guard is covered
directly for the archive types that share it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The zip and tar readers swallowed read failures and returned an empty
iterator, which the hashing path can't tell apart from an empty archive:
it falls back to hashing the container's raw bytes, so the ROM gets
hashes that match no hash database and nothing explains why.
Raise ArchiveReadError instead, as the 7z and rar readers already do, so
the fallback is logged. Member streaming is now wrapped too, since chunks
are consumed outside the reader's error handling and a bad CRC escaped as
a raw zipfile error rather than falling back.
Fixes#4159
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
miximage and miximage_v2 both mapped to the assets/miximages directory and to
the <miximage> tag, so the v2 art was dropped by the existing-destination
short-circuit in _copy_asset and the XML carried a duplicate tag. Route the v2
variant to assets/miximages_v2 and the <miximage_v2> tag, matching the folder
and tag the gamelist handler already reads back.
The gamelist handler discovers back covers and fanart (ES-DE backcovers/ and
fanart/ folders, <backcover> and <fanart> tags) but never recorded a local
path for them, so the gl.get("box2d_back_path") / gl.get("fanart_path")
fallbacks in both exporters could never resolve. Record those paths alongside
the media types the handler already persists, and declare title_screen_path,
which populate_rom_specific_paths already emitted.
Fixes#4128