feat: opt-in per-platform subfolder scanning with non-destructive identity

Adds opt-in, per-platform subfolder scanning (closes #2050). When enabled
for a platform, RomM recurses that platform's subfolders and treats each
nested file as its own ROM, instead of collapsing a subfolder into one
multi-file ROM — so libraries organized into Hacks/, Translations/,
Homebrew/, etc. are scanned correctly.

Enable per platform in config.yml (default off, existing setups unaffected):

  scan:
    subfolders:
      nes: true                       # recurse every subfolder
      snes: ["Hacks", "Translations"] # recurse only these; keep others whole

Key difference from a naive path-identity approach: identity is reconciled
by content hash on scan. Moving or renaming a ROM between subfolders is
detected by its hash against a now-missing ROM and relocated in place, so
saves, play history, favorites and collection membership follow it. Falls
back to path identity when hashing is unavailable (skip_hash_calculation or
a non-hashable platform). A cheap size pre-filter avoids hashing every
newly-seen file (e.g. on first enable).

Details:
- Per-platform opt-in via scan.subfolders (fs_slug -> bool | list[str]); no
  DB schema change.
- Recursion skips hidden (dot-prefixed) folders, and keeps a folder whole as
  a single multi-file ROM when it holds a disc/playlist descriptor
  (.m3u/.cue/.gdi/.ccd/.toc) — covers cue+bin / multi-disc games.
- Path-based keying for the steady-state lookup (get_roms_by_fs_name and
  mark_missing_roms key on full path) so identically-named files in different
  subfolders stay distinct; the (platform_id, fs_name) index is non-unique.
- File resolution (download/delete/hash) uses the ROM's stored fs_path.
- Scan log flags entries that became "missing" because a folder is now
  recursed, so stale entries are easy to clean up.
- Frontend: the Files tab shows a ROM's on-disk Location (click-to-copy),
  built as a shared LocationChip mirroring HashChip's RTag-based pattern.
  New i18n keys added to all locales.

Tests: backend unit tests for recursion (collisions, hidden folders,
descriptor dirs kept whole, named-list form), full-path keying in
get_roms_by_fs_name / mark_missing_roms, and hash-based relocation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sk2dzM3K9qxWBdPAeGb7us
This commit is contained in:
Claude
2026-06-21 20:46:50 +00:00
parent 49f2b1659c
commit 5b494c3bc4
28 changed files with 951 additions and 100 deletions

View File

@@ -145,6 +145,38 @@
# image: screenshot # Use as the <image> tag in the exported gamelist.xml
# pegasus:
# export: false # Whether to export metadata.pegasus.txt for Pegasus
# # Recurse into platform subfolders, treating nested files as their own
# # ROMs rather than collapsing each subfolder into a single multi-file ROM.
# # Opt-in per platform. The value is either:
# # - true -> recurse EVERY subfolder of the platform;
# # - a list of folder names -> recurse ONLY those folders, leaving every
# # other folder as a single multi-file ROM (so folder-based multi-file
# # games elsewhere on the platform stay intact — the recommended form
# # when a platform mixes grouping folders with multi-file games);
# # - false / omitted -> default behavior (a subfolder is one multi-file ROM).
# #
# # Behavior & notes (read before enabling):
# # - Hidden (dot-prefixed) folders are never descended into.
# # - A subfolder containing a disc/playlist descriptor (.m3u, .cue, .gdi,
# # .ccd, .toc) is kept whole as a single multi-file ROM (a multi-disc
# # game) and is NOT split into one ROM per disc, even when recursed.
# # - With `true`, a multi-file game stored as a bare folder with no such
# # descriptor WOULD be split into separate ROMs. Use the named-list form
# # (don't list that game's folder) to keep it whole.
# # - Identity is content-based on scan: moving (or renaming) a ROM between
# # subfolders is detected by its hash and relocated in place, so its
# # saves, play history, favorites and collection membership follow it —
# # as long as hashing is enabled and the platform is hashable. When a
# # folder previously scanned as one multi-file ROM is now recursed, that
# # old entry is marked "missing from filesystem" (the scan log flags it);
# # delete the stale entry to clean up.
# # - Two files with the same name in different subfolders become distinct
# # ROMs; gamelist.xml metadata matching is by filename, so both may match
# # the same gamelist entry.
# subfolders:
# nes: true # recurse every NES subfolder
# snes: ["Hacks", "Translations"] # recurse only these; keep other folders whole
# megadrive: false
# EmulatorJS per-core options
# emulatorjs: