Files
romm/backend/handler/database
Zurdi 27780d8439 fix(management): preserve ROM metadata when files move (#5795)
* Preserve ROM metadata when files move

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(scan): keep the filename fallback from overriding stronger matches

Address Greptile and Copilot review on #5795:
- Fold the filename into get_matching_missing_rom as its weakest tier, so an
  ambiguous hash or title id match stops the search instead of falling
  through to a filename.
- Compare filenames with exact_collation, so MariaDB's case-insensitive
  collation can't match game.zip to Game.zip.
- Skip the filename tier for names several discovered files share, so one
  copy can't take an entry that another copy's hashes would have claimed.
- Fix the present-ROM test, which stored Present.zip.zip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

- Skip filename matches on entries whose stored hashes or title id show
  another file.
- Exclude physical games from reassociation.
- Keep a plain fs_name comparison so the platform/fs_name index applies.
- Match on the discovered name, before title id embedding renames it.
- Make the shared-name scan test able to fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose (code-review additions)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(scan): claim a missing entry atomically before reassociating it

Files are identified concurrently, so two files could match the same
missing entry and both move it. claim_missing_rom clears the missing
flag with a conditional UPDATE, and only the file whose claim wins moves
the entry; the other gets a new one.

The reassociation log line now names the identity that matched (file
hash, title id or filename), so a wrong filename match can be traced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(db): pass hashes explicitly so mypy accepts the call

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(streaming): run the app lifespan in the ASGITransport claim tests

The two async claim tests read app.state.aiohttp_session through the
context middleware, which only the lifespan sets. They passed only when
an earlier test on the same worker had opened a TestClient.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 08:40:59 -05:00
..