When extracting the largest member of a .7z failed partway, the bytes already
streamed stayed in the file and ROM-level hashers, and the raw-archive
fallback was appended on top, giving a hash that matched neither. The hashers
are now restored to their pre-extraction state before the fallback runs.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* perf(scan): download a rom's media files concurrently
download_rom_resources fetched the cover, manual, each screenshot, each
provider media type and every RetroAchievements badge one after another,
so a single ROM never used more than one of the ScreenScraper account's
request slots.
They now download together. ScreenScraper media still goes through its
existing thread and rate limiters, and badges share a new cap of 8 in
flight across all scans. The path columns and changed provider media
dicts are written back in one update.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
* style(tests): sort imports with the Trunk isort config
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
* fix(scan): code-review fixes for concurrent media downloads
- Run provider media dicts one after another, since they share paths
- Await every download before raising the first failure (gather_all)
- Fetch each duplicate media or badge path once (store_ra_badges)
- Reuse store_ra_badges in update_rom
- Share the in-flight test helper and trim comments
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
* refactor(scan): simplify pass on concurrent media downloads
- Move gather_all to utils/concurrency and unpack its results directly
- Let write_file_streamed create the badge directory instead of every badge
- Share the in-flight test helper through tests/concurrency_stubs
- Stub downloads with AsyncMock through one fixture, drop a redundant test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
* fix(scan): save the paths that landed when a provider download fails
Cover, manual and screenshot paths are written before a provider media or
badge failure is re-raised, so a failure there no longer loses them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
* fix(scan): save each download group's results independently
Paths, provider media and badges each keep their own outcome, and every
change that landed is written before the first failure is re-raised. The
test builds a real Rom instead of a namespace.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* chore(mypy): switch to strict mode with listed exceptions
Replace the hand-picked flags with `strict = True`, turning off only the
four flags that aren't clean yet (disallow_any_generics,
warn_return_any, disallow_untyped_calls, disallow_untyped_decorators).
Any other strict flag, including those future mypy releases add to the
preset, is on by default.
That turns on no_implicit_reexport, strict_equality and extra_checks:
- Import each name from the module that defines it. About 240 test
sites patched a dependency through the module that imported it
(`scan_module.fs_rom_handler`); they now import the same object from
its source, so every patch targets what it did before. Tests that
replace a module attribute are unchanged.
- handler.streaming.memory_cards re-exports store_memory_card_version
explicitly, since endpoints call it there and tests patch it there.
- mutagen gets implicit_reexport, as it re-exports without __all__.
- Test comparisons build typed values (CoverResult, a typed expected
dict, enum .value) and the CORS lookup casts for its identity check.
- One ss_handler ** spread keeps a coded ignore: extra_checks wants its
NotRequired dump_* keys spelled out, and the media dict never has them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
* chore(mypy): give every generic its type arguments
Drop disallow_any_generics from the strict-mode exceptions and fix the
347 bare generics it reports, 230 of them in app code.
- Bare `dict` becomes `dict[str, Any]`: update payloads, raw provider
JSON and endpoint bodies map string keys to mixed values, so the Any is
real and now written down. The OpenAPI document is unchanged.
- Rom query filters take and return RomSelect; _music_facet_joins and
_exclude_hidden are generic over the Select they're given, and
_build_hash_selects returns id-only selects.
- Redis clients are typed by what they return: the decoding caches are
Redis[str], the RQ connection and binary cache Redis[bytes].
- The rest get explicit parameters: Row, Pattern, ColumnElement,
QueryableAttribute, SpooledTemporaryFile, Task, Future and friends.
Precise types reached callers that had been getting Any, which surfaced:
- The LaunchBox cache writer is fed binary-cache pipelines.
- The flashpoint and IGDB request helpers return raw JSON of varying
shape, not always a dict.
- The rom search endpoint returned dicts under a list[SearchRomSchema]
annotation; it now validates them into that schema.
- The audit filter's id subquery selects strings.
- In tests the binary cache is the non-decoding fake shared with
async_cache, so it is cast to Redis[bytes] rather than changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
* test(upload): assert cleanup against the patched upload directory
The 409 test checked config's ROM_UPLOAD_TMP_BASE while the fixture patches
the endpoint's copy to tmp_path/uploads, so it passed even if cleanup failed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
* chore(mypy): keep the row type through the ROM filter helpers
filter_roms and its helpers also receive select(Rom.id) membership queries,
so they now take and return the caller's Select type instead of narrowing to
RomSelect. merged_ra_metadata mixes scalar and list values.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
compare_save_state decides a side changed from its timestamp, and
emulators rewrite a save on exit, so an untouched save looks new and a
server change elsewhere turns into a false conflict.
device_save_sync now records what each side held at the last sync
(last_sync_hash from the device, last_sync_server_hash from the server,
migration 0140). A baseline match proves that side unchanged; a mismatch
or NULL falls back to the timestamp logic, so this only removes
conflicts. It runs after the removed_at check in compare_save_state.
- Baselines are recorded only for versions the device provably holds:
confirm_download pins to the served version, update_save records the
client hash only when the file was uploaded, deduplicated uploads and
pushed saves record against the surviving save, and push-pull no-ops
record hashes only for identical content.
- Identical-content no-ops in negotiate and the watcher record a
boundary without re-tracking untracked saves.
- The SSH push-pull and file-transfer watcher paths hash device saves
through hash_save_file, matching compute_content_hash for zipped
saves, and treat unreadable saves as unknown.
Squashes rommapp/romm#4768 onto master.
Claude-Session: https://claude.ai/code/session_01WAKUdfLb6fyduEqaFbf5A8
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- Move unrecorded_hash onto FSAssetsHandler, so sync_watcher and the
push-pull task no longer import handler.asset_store (and with it
scan_handler and every metadata provider, ~80 modules)
- Drop the PSP bundle's unrecorded_hash call: bundles are never slotted
- Skip the removal-times query when the device's copy already matches
- Restore per-row deletes in prune_slot: the single `id IN (...)` delete
from the review pass deadlocked the threaded removal test 3/10 runs on
MariaDB (0/25 per row)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Key PSP member hashes on the bundle's content hash, computed once in a
thread, cached via the shared batch helper, and guarded only on write
- Build only the requested tree for a PROPFIND listing
- Walk blobs with iter_files, share the bundle limit check and reader
- Drop the derivable ManifestAsset.parent_path and the closure factories
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Read every asset and blob hash from one MGET, compute misses with
bounded concurrency and write them back in one pipeline.
- Split the manifest into a path builder and a hashing layer; PROPFIND
of saves/ and states/ now lists paths without hashing assets, walking
blobs or inflating PSP bundles (member names come from the zip
central directory).
- Walk blob directories once off the event loop with os.scandir, reusing
each entry's size and mtime for the hash cache key.
- Build PSP bundles off the event loop and prime the member-hash cache
on write so the next manifest skips inflating them.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
RetroArch names a slot's state the same under every core, and its
screenshot was filed per ROM, so two cores' `<rom>.state.png` shared
one file and one row. File them under a per-core screenshots folder,
upsert by path, and only match a state to a screenshot in its own core's
folder or the ROM-level one.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Enforce the upload size cap on streamed bytes in the middleware, so
chunked uploads to every guarded route are bounded, not just RetroArch
- Flag vanished assets missing_from_fs from the manifest instead of
re-hashing them every sync
- Batch state screenshot lookups, filter PSP bundles in SQL, hash files
in one thread hop, and read only the requested PSP bundle members
- Reuse remove_screenshot and content_hash_of_bytes, merge the save and
state PUT branches, drop dead checks and trim docstrings and tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Every manifest read (GET and each PROPFIND) hashes every save and state
row, and failures aren't cached, so a DB row whose file is gone logged a
debug line on every sync. A missing file is expected there; other OSErrors
are still logged.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
FSRetroArchSyncBlobHandler becomes FSRetroArchSyncHandler, and
SYNC_RETROARCH_BLOB_BASE_PATH becomes SYNC_RETROARCH_BASE_PATH, stored
under /romm/retroarch_sync.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The manifest protocol is RetroArch's own, so name it after RetroArch
rather than its WebDAV transport, and group it with the existing sync
code: endpoints/sync/ becomes a package with the RetroArch router as a
subroute, and the handlers move under handler/sync/retroarch/. Settings
move into the SYNC config section as SYNC_RETROARCH_*.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Keep a shared thumbnail in place when its new name resolves to the same
file, so a case-only rename on a case-insensitive filesystem no longer
fails with a conflict trying to copy the thumbnail onto itself.
- Build the user in the collection dialog tests with a typed userFixture
instead of casting a partial object.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Group the handler modules under handler/webdav_cloud_sync/ (sync_handler,
psp, emulator_names, browser) and rename the endpoint, blob handler, tests,
config settings, storage folders and cache keys to match. The route moves
from /api/cloud-sync to /api/webdav-cloud-sync.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Resolve PSP folder paths from the same bundle set the manifest lists
(visible ROM, unslotted, newest per folder), so GET/PUT/DELETE can no
longer hit a slotted history bundle or a hidden ROM's bundle.
- Split validate_path's base-directory case out of its startswith guard,
so CodeQL recognizes the guard as a py/path-injection sanitizer.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Hoist the file MD5 onto FSHandler; drop the blob handler copy
- Share path splitting, slot recency, cached MD5 and ROM visibility helpers
- Remove dead code (get_state_by_path, RomFile.file_ids, unused params)
- Scope WebDAV rom listing to one query; look up a single platform by slug
- Query saves once per manifest and batch ROM name resolution
- Read only the requested PSP bundle member; hash bundles from memory
- Single separator-safe lexical check in validate_path; same joined-path
validation in write_file_streamed
- Stop stripping + on ROM rename, the download path encodes it (#2746)
- Trim comments to the repo's comment rules
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- A shared thumbnail stays untouched only when the rename keeps its name
exactly; a case-only change gets its own copy, since PostgreSQL matches
screenshot names case-sensitively.
- copy_to_new_file removes the file it created when the fallback copy fails
partway, so a retry does not meet a half-written thumbnail.
- rename_asset's docstring drops a Returns block the signature already says.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A shared thumbnail whose stem the rename keeps stays as it is, instead of
being copied onto itself.
- The thumbnail copy goes through FSHandler.copy_to_new_file, which links or
creates exclusively, so a screenshot another worker wrote at that name is
refused instead of replaced.
- Collection settings hand a saved collection to the parent only while it is
still the one on screen, so a late visibility or Apply answer cannot swap
in the collection the user navigated away from.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Bound /api/cloud-sync uploads with the asset size limit
- Cap PSP bundle member count and uncompressed size
- Keep PSP writes and deletes on the existing bundle row, one member at a time
- Match PSP bundles by exact folder, support the no-core-folder layout
- Reject . and .. PSP segments; map parse_sfo struct errors and write
errors to 4xx
- Require ROMS_READ for roms/ browsing
- Clear missing_from_fs on overwrite
- Resolve state screenshots by exact name, never a gallery screenshot
- Round-trip unknown core folder names exactly
- Keep + allowed in the shared sanitizer, strip it only on ROM rename (#2746)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- rename_file links then unlinks, so a name another worker took after the
check is refused instead of replaced; filesystems without hard links fall
back to rename.
- rename_asset owns the whole rename: the thumbnail and asset rows commit
in one transaction, and a failed commit moves the files back.
- A thumbnail another save or state still resolves is copied for the
renamed asset instead of moved away from the other one.
- Collection Apply and the visibility switch wait for each other.
- The collection settings test builds its fixture with a typed factory,
the RSwitch label-slot story uses a colour token, and the moved assets
fixture keeps a one-line docstring.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The remaining py/path-injection alerts flowed through write_file's
filename argument (cloud-sync blob PUTs), which only went through
os.path.basename. Validating the full directory + filename path routes
it through validate_path's normpath guard too.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Swap xml.sax.saxutils.escape for html.escape(quote=False), which bandit
does not flag as an XML parser import. Add a normpath + startswith guard
to validate_path so CodeQL recognizes it as a path-injection sanitizer.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Saves and states could only be renamed by downloading, renaming and
uploading them again (#2653).
Backend: PUT /api/saves/{id}/file-name and PUT /api/states/{id}/file-name
rename the file on disk and the row, and take the auto-captured thumbnail
along so it stays bound by stem. A name another save/state of the ROM
holds, or one that would bind another screenshot, is a 409. Renaming
keeps updated_at, like the other annotations, so device sync does not
see a new version.
Frontend (v2): the Save data tab's per-row actions are now download,
edit, favorite and delete. Edit opens one form with the file name (stem
preselected), labels and visibility; a taken name is flagged in the
field. Public saves and states carry the same globe badge as shared
screenshots. RTextField now puts `autofocus` on its native field, which
is what RDialog looks for, so autofocused fields in dialogs get focus
instead of the close button.
Fixes#2653
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(metadata): read a fan translation's tag and target language
A translated dump is playable in the language it was translated into, but the
tag saying so was kept verbatim, so the rom was filed under no language at all
and the filter drawer grew one throwaway value per patch: "T+Eng1.1_RPGe" and
"T-Eng0.98_DeJap" are the same thing to a reader and two different facets to
the gallery.
The GoodTools, TOSEC and plain spellings now resolve to one "Translation" tag,
and the language the patch targets joins the rom's languages, so a Japanese
game translated into English answers a search for English and reaches an
emulator as English. A translation into a language RomM cannot name is still
tagged, and a tag that merely starts with "tr", like "Trainer", is left alone.
The group and patch version the raw tag carries are dropped, since nothing
reads them and keeping them is what splits the facet.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC
* feat(metadata): read the spaced form of a GoodTools translation tag
"[T Fre]" separates with a space rather than a sign, and it is the spelling a
real ScreenScraper dump carries: its entry for "Super Mario Bros. (W) [T Fre]"
is flagged as a translation into French. The tag was read only as "T+Fre" or
"T-Fre", so that dump came out untranslated and unlanguaged.
A space carries no meaning of its own, unlike the sign, so this spelling counts
only when the word after it names a language: "(T Rex)" stays an ordinary tag.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC
* style(metadata): trim the translation alias comment to two lines
Greptile flagged it against the repo's comment discipline: four lines, and
the product as the actor.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC
* feat(metadata): resolve the short forms of a translation tag's language
"[T-En]" already resolved through the filename language vocabulary; the
non-ISO abbreviations "Ge", "Sp", "Du", "Gr" and "Jp" did not, so those
dumps were tagged without a language. Tests now cover both forms.
Also trims three comments and four test docstrings Greptile flagged
against the repo's comment discipline.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC
* fix(metadata): stop reading a hyphenated word as a translation
"(T-Rex)" matched the GoodTools superseded form and became a Translation
tag. A superseded patch carries its version and group, so require that,
or a language the vocabulary names, before the bare "T-" form counts.
"[T+Tha]" still tags, since no ordinary word takes that shape.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC
* style(metadata): trim the translation regex comment to two lines
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Addresses Greptile's review of #4613:
- Write the small cover and the WebP copies in a worker thread, since
Pillow's work now scales with an animation's frames.
- Annotate the new converter fixture and the artwork test's tmp_path.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Simplify pass over the animated cover change:
- Encode animated small covers as WebP whatever the source, which drops
the per-format GIF/APNG blending params and makes their WebP copy a
plain file copy.
- Fold the is_animated gate into frame_durations and decode the small
cover's frames in the same pass that reads their durations.
- Write uploaded animated artwork through the atomic write_file.
- Share test fixture constants and the animation encoder, and pin the
per-frame pixel budget with a GIF whose canvas grows mid-animation.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Code-review pass over the animated cover change:
- Cap the pixels decoded across an animation (MAX_ANIMATION_PIXELS),
counted per frame since a GIF canvas can grow mid-animation, so an
oversized animation falls back to its first frame.
- Fall back to the first frame when a later frame fails to decode,
instead of dropping the cover or escaping the error handlers.
- Store uploaded animated artwork as uploaded, like downloaded covers.
- Re-encode composited frames so each replaces the last (no GIF/APNG
ghost trails), and keep GIF loop counts when converting to WebP.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The small cover and the WebP copies were written through PIL, which keeps
only the first frame, so an animated SteamGridDB cover showed as a still
image everywhere once applied. Resize and convert every frame with its
timing, copy WebP sources instead of re-encoding them, and keep all
frames of uploaded animated artwork.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`directory_exists` and `Rom.full_path` already spell out the check the
scan does at its own call site, so the path is no longer rebuilt here.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Name the candidate predicate for what it checks, trim the ordering
docstring, and drop the comments the moved guards made stale.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sort title id sources with the natural key the models already compute,
give the compressed suffixes one home, and let SigilService reject a
container itself rather than trusting every caller to.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Order discs by their number so "Disc 2" precedes "Disc 10", test one
rule for containers sigil cannot read, and drop the unreachable
OSError handler around Path.is_file.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A folder the scanner maps to a media category now refuses files that
category cannot hold inside resolve_upload_destination, so the chunked
flow the v2 tabs use gets the same allowlist the media routes had, and
those routes drop their own copies. commit_upload records an upload
provenance for walkthrough files that arrive without one and returns the
registered row, which the walkthrough route uses for author and title.
The refresh lock moves to Redis so uploads landing on different gunicorn
workers cannot drop each other rows. An empty body filename is rejected
instead of falling back to the header.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>