Introducing a new way to review your PRs.

Read the announcement

rommapp / romm

A beautiful, powerful, self-hosted ROM manager and player.

View on GitHub

22 documents · Updated Nov 23, 2026

docs / library-scanning-and-filesystem

Library scanning and filesystem handling

Library scanning turns the configured library tree into catalog records. It discovers platforms, ROMs, ROM parts, and firmware, then reconciles that view with stored records while keeping metadata, local resources, and user-owned files separate from the ROM source tree. User-scoped emulator sync data also stays in asset storage instead of becoming part of the ROM library. The scan preserves known identity when a provider is unavailable or when a file moves without a safe match. See the Game library catalog page for the wider catalog model, Catalog data and API for record access, Metadata enrichment for provider lookups, and Recommendation delivery for downstream catalog use.

Library layout

The library uses a platform-first layout with configurable ROM and firmware folders. The scanner supports a shared ROM root and custom per-platform structures so an existing library can be read without a forced move.

Folder structures

The default patterns are:

LayoutROM locationFirmware location
Shared ROM root<library>/<roms-folder>/<platform><library>/<firmware-folder>/<platform>
Platform ROM root<library>/<platform>/<roms-folder><library>/<platform>/<firmware-folder>

Configured structure templates can add nested category or game folders. The scanner combines templates and removes duplicate paths. A folder that is a game in one template is not scanned again as a grouping folder in another template. The shared root remains the preferred default when both layouts are present.

If the platform folder does not exist, the scanner creates it and reports an empty library. In a custom structure, a top-level folder counts as a platform only when the configured structure can reach its ROM location. Platform aliases and version mappings connect a filesystem folder to a known catalog platform when their names differ. Excluded platform patterns are removed before the scanner touches those folders.

References: backend/…/platforms_handler.py• L16-25 backend/…/platforms_handler.py• L27-44 backend/…/platforms_handler.py• L59-79 backend/…/roms_handler.py• L1316-1389

ROM discovery

For each platform, the scanner treats a direct file as a flat ROM and a direct directory as a nested or multi-file ROM. It follows the configured structure templates, ignores hidden and excluded entries, and removes duplicate discoveries before scan work begins. Files inside a nested ROM become file records that describe the game, its parts, and any special media.

Discovery first records each ROM's location and shape. The scan reads file bytes only when the selected scan mode needs hashes, title IDs, metadata matching, or a rebuilt file view.

The file name supplies an initial identity. Bracketed tags can provide region, language, version, revision, and other catalog facets. Revision tags support both separated forms such as Rev 01 and compact numeric forms such as Rev01. Known region and language aliases are normalized to one catalog value, while other tags remain available as user-facing tags. Translation markers become a common translation tag and can add the language named by the marker. Folder names can mark manuals, patches, DLC, cheats, screenshots, and soundtracks; the category normally comes from the first category folder below the ROM root, while patch file names are recognized in any folder.

Archives are represented by one source file with member details rather than by invented paths inside the archive. Supported formats and CHD files use the content that represents the game for hash matching. An unreadable archive falls back to the archive file's own identity. A file is treated as a real ZIP archive only when its archive data starts at the first byte; a state file that merely ends with ZIP data remains a single raw file. A PICO-8 cartridge PNG can serve as its own cover when no other cover is available.

Some supported formats carry platform identity. Title ID extraction is independent of hash support, so a non-hashable platform can still provide a stable identity. The scanner can combine platform-specific readers for title IDs, versions, save targets, and content types while retaining one ROM identity. For multi-file games, eligible binary files across the game can provide that identity, while manuals, soundtracks, screenshots, cheats, sidecar files, unreadable archive formats, and other non-binary resources cannot. Readable archive files can still provide identity when a supported reader can inspect them. When configured, a Switch title ID is embedded in a file name after extraction; the resulting ROM path is reconciled as part of the same scan.

References: backend/…/base_handler.py• L45-67 backend/…/base_handler.py• L101-115 backend/…/roms_handler.py• L232-256 backend/…/roms_handler.py• L361-402 backend/…/roms_handler.py• L788-1263 backend/…/roms_handler.py• L1316-1502

Physical game records

A physical game is a catalog record for owned media that has no ROM file on disk. Manual creation gives it a reserved catalog-only location, so filesystem scans do not discover or mark it missing. It remains part of the catalog while reconciliation applies only to file-backed entries.

References: backend/…/scan_handler.py• L87-110 backend/…/scan_handler.py• L209-227 backend/…/roms_handler.py• L2250-2273

ROM file identity

Hashing gives the scanner a stable identity when a ROM is renamed, moved, or stored in a container. A flat ROM uses its file content. A nested ROM combines its top-level files. An archive keeps member details while also producing a game-level identity. The scanner uses the content that represents the game instead of treating archive members as separate filesystem paths.

The scanner reuses stored file rows when size and modification time show that a file is unchanged. For nested ROMs, a change at the top level causes the game-level hash to be rebuilt when the scan requests ROM hashes. Hashing can be disabled or unavailable for some platforms. In those cases the scanner still records the files and can use names, metadata, and extracted title IDs, but it cannot use a hash-only match. Title ID extraction and file renaming remain separate from hash calculation, so identity can still be read on a platform that has no hash database. A scan that only needs file rows or title IDs can keep the stored game-level hash instead of rereading unchanged content.

A quick scan uses this incremental view for known ROMs: it reconciles file rows with the current directory and does not repeat the full ROM inspection path for an unchanged entry. Complete and hash scans are the explicit byte-reading paths when the catalog needs a full rebuild or fresh identity values.

References: backend/…/assets_handler.py• L207-305 backend/…/assets_handler.py• L460-480 backend/…/roms_handler.py• L307-361 backend/…/roms_handler.py• L788-1263 backend/…/scan_handler.py• L582-682 backend/…/scan.py• L591-610

Scan lifecycle

A library scan moves from the filesystem view to the catalog view. It finds platform folders, discovers firmware and ROMs, inspects files when needed, applies metadata, and then marks records that are no longer present.

Platform and file passes

The scan resolves each filesystem platform to a catalog platform before it reads the platform's content. It performs the firmware pass first, then discovers flat and nested ROMs. A ROM can be represented by location alone until the scan decides that file inspection, hashing, or metadata work is needed.

The ROM pass matches the discovered location to existing records and processes work in bounded batches. Unchanged entries can be marked present in bulk, while new or selected entries are inspected and enriched. A quick scan refreshes the files of a known ROM without repeating provider work. This limits filesystem and provider work while keeping a broad scan responsive.

This diagram shows the normal platform-wide scan path.

flowchart TD
    A[Configured library root] --> B[Discover platform folders]
    B --> C[Resolve catalog platform]
    C --> D[Discover firmware files]
    D --> E[Discover flat and nested ROMs]
    E --> F[Match filesystem location]
    F --> G[Inspect and hash changed files]
    G --> H[Apply catalog metadata]
    H --> I[Reconcile ROM files and resources]
    I --> J[Mark absent records missing]
    J --> K[Refresh derived catalog views]

Selected-ROM scans use database records as their work list. They check the selected paths and do not run the platform-wide directory walk, firmware pass, or missing-record pass.

References: backend/…/scan.py• L533-610 backend/…/scan.py• L821-905 backend/…/scan.py• L932-1141 backend/…/roms_handler.py• L1392-1416

Scan modes

The scan type controls how much local identity and provider data is rebuilt. Quick work finds new files and reconciles known ROM files. Update work refreshes known matches. Unmatched work fills missing provider identity. Complete work rematches the catalog and resets selected resource state. Hash work focuses on file identity and hash-based matches.

ModeMain useFilesystem and catalog effect
QuickFind new library contentAdds new ROMs and reconciles the files of known ROMs without repeating their full scan
New platformsAdd platforms not in the catalogSkips existing platform records
UpdateRefresh identified recordsReuses stored file data and refetches selected matches
UnmatchedFill missing identity dataTargets records without selected provider identity
CompleteRebuild the catalog viewRe-reads ROMs, clears deselected or conclusively rematched source data, and rebuilds resources
HashesRecalculate identityRebuilds file identity without the normal resource pass

Scheduled rescans use a quick scan across filesystem platforms and enabled metadata sources. Direct requests can select platforms or ROMs. The scan reports progress, rejects duplicate active library scans in normal operation, and checks for a stop request between work units. A complete scan clears source data only for providers it actually consulted or providers no longer selected. An unavailable provider is treated as inconclusive, so a temporary outage does not erase a known match.

Hash-based providers can also supply region, language, and other dump tags. The scan keeps those claims with the source that supplied them, then uses them only when local tags or higher-priority metadata do not provide the value. A conclusive hash scan can remove a stale verification match; an unavailable hash provider cannot.

References: backend/…/scan.py• L379-541 backend/…/scan.py• L1144-1405 backend/…/scan.py• L1406-1489 backend/…/scan_handler.py• L582-711 backend/…/scan_handler.py• L1419-1510

Scan control

The scan socket is a privileged entry point that starts, queues, and stops scan jobs. A broad library scan runs through the scan queue so only one active library pass is accepted in normal operation. A selected-ROM scan can move ahead of queued library work because it reads its work list from the catalog.

The stop request cancels queued jobs and sets a stop flag for a running job. The running scan checks that flag between platforms and ROMs, then reports a stopped result. If a worker ends before it can emit its terminal event, the job failure path emits a failure event so clients do not show a scan that is still running. A completed scan also refreshes derived filters, smart collections, identity statistics, similarity data, and any configured metadata exports. A selected-ROM scan refreshes only the smart collections touched by those ROMs.

References: backend/…/scan.py• L123-181 backend/…/scan.py• L1194-1231 backend/…/scan.py• L1394-1489 backend/…/scan.py• L1495-1612

Catalog reconciliation

Reconciliation keeps the database aligned with the current filesystem without destroying catalog state during a move or temporary unmount. It uses the filesystem location for the common case and content identity for recovery.

ROM record matching

The scanner first matches a discovered ROM by platform and full filesystem location. If that record is not present, it checks records marked missing. A single complete hash match moves the old record to the new location and clears its missing state. On a non-hashable platform, an extracted title ID can provide the same recovery path.

The recovery match requires all three supported hashes or one title ID. It is limited to the same platform and refuses to choose when more than one missing record matches. The scanner creates a new record when identity data is incomplete or ambiguous. This avoids attaching a file to the wrong game and preserves collections, notes, and user assets when a move is unambiguous.

A scene production is a demoscene work identified by Demozoo, Pouët, or CSDb. Once a ROM has one of these source IDs, later scans keep those scene sources in control of its title and artwork. A provider outage does not make the record fall back to a similarly named retail game. A complete scan clears that identity only when the source is no longer selected or the source is deliberately reset.

References: backend/…/scan_handler.py• L191-207 backend/…/scan_handler.py• L1419-1464 backend/…/scan_handler.py• L1466-1486 backend/…/scan.py• L1028-1037

Missing record state

Missing state describes the difference between the catalog and the current filesystem. Before a platform ROM pass, the scanner compares stored full locations with the current keep-list. It writes only state changes. Discovered entries are marked present, and entries left outside the keep-list are reported as missing.

Physical games are excluded from this comparison because they have no source file to lose. A missing platform can still make its file-backed ROMs unavailable to the catalog. When a missing ROM returns, the scanner clears the state and clients receive the refreshed record. This keeps a temporary unmount from becoming data loss.

References: backend/…/scan.py• L1028-1037 backend/…/scan.py• L1058-1136 backend/…/roms_handler.py• L2200-2289 backend/…/platforms_handler.py• L127-161 backend/…/scan_handler.py• L209-227

Missing-record cleanup

Manual cleanup is the explicit removal path for records that remain missing. It can be limited to selected platforms and reports found, removed, and failed records.

  • ROM cleanup deletes missing ROM records and then removes their stored catalog resources.
  • Firmware cleanup deletes only missing firmware records.
  • Present records are not eligible for either cleanup path.

References: backend/…/cleanup_missing_roms.py• L36-93 backend/…/cleanup_missing_firmware.py• L34-84 backend/…/roms_handler.py• L1231-1241

ROM file rows

Each ROM record can have rows for its physical files and their important metadata. A fresh scan reconciles those rows instead of replacing them blindly. It matches by path first and then by a complete content key when that key identifies only one existing row. A moved file can therefore keep its row identity and track metadata without an unsafe guess. Rows that no longer exist are removed, and soundtrack cover files left without a track row are cleaned up.

ROM file refreshes are serialized per ROM. An empty result is treated as a possible mount loss when rows already exist, so a transient filesystem failure does not look like a valid deletion of every file. The refresh updates scanner-owned file and track values while retaining stored values that the scan did not produce. It also updates ROM size, hashes, and extracted identity only when the scan has reliable values.

References: backend/…/roms_handler.py• L244-315 backend/…/roms_handler.py• L2401-2529 backend/…/roms_handler.py• L307-361 backend/…/roms_handler.py• L788-1263

ROM file access

ROM file rows provide the catalog-controlled bridge from a ROM record to its source content. File access first checks the parent ROM and its visibility, then uses the stored file category and name to choose safe browser display or download behavior. Deletion removes the source file and its row together, while document-category files also support per-user reading progress.

This keeps file access tied to the catalog record rather than to a client-supplied path or file type. It also lets manuals and walkthroughs use the same scanned file relationship as game files and soundtracks.

References: backend/…/files.py• L40-163 backend/…/files.py• L166-221 backend/…/files.py• L224-331

Firmware records

Firmware is discovered beside the ROM tree but remains a platform-linked firmware record rather than a ROM record. The scan stores its path, name, size, and hashes. Known firmware identities can then mark the file as verified.

The scanner reuses a firmware record when platform and file name match. It avoids reading bytes when the stored path and size still describe the discovered file, and reads bytes for new or hash-focused work. A file that disappears is marked missing, so firmware stays visible during a library outage without being confused with a ROM.

References: backend/…/firmware_handler.py• L13-55 backend/…/scan_handler.py• L239-270 backend/…/scan.py• L326-376 backend/…/scan.py• L968-985 backend/…/scan.py• L1129-1136 backend/…/firmware_handler.py• L12-126

ROM resources

ROM resources are local files linked to catalog records. They include covers, screenshots, manuals, provider media, and achievement badges. The scan fetches or retains them after the ROM record is saved, so these files do not become part of the source ROM tree.

Resource refresh

Normal scans keep a resource when its source has not changed or its local copy is usable. Resource sources can be provider URLs or local-file references from metadata such as a gamelist or LaunchBox. Local covers are copied into the resource area so a later rewrite does not change the user's source file. Complete scans remove old downloaded resources before new metadata is stored.

Provider media can share a resource path across metadata sources. The scan removes stale media only after comparing the old and new provider records together, then lets each enabled source keep a usable file that is already present. A source that fails does not discard media that another source stored successfully.

Resource downloads accept only the media types expected for the resource. HTTP media marked as gzip is decoded before it is stored, and the size limit applies to the decoded body. Interrupted, undecodable, partial, and known placeholder images are removed instead of being treated as valid resources. This lets a later scan retry the source. Provider media is stored only when its selected source supplies it and the download succeeds. If a media path is recorded but no usable file remains, the path is cleared while its source URL stays available for a later retry. A PICO-8 cartridge image can supply a cover without a separate download.

Screenshots are reused from the files on disk rather than from a stale recorded list. This allows a failed earlier write to be retried on a later scan. Animated artwork remains animated while the system also produces the sizes and formats needed by catalog clients.

References: backend/…/resources_handler.py• L40-67 backend/…/resources_handler.py• L247-375 backend/…/resources_handler.py• L417-446 backend/…/resources_handler.py• L596-655 backend/…/resources_handler.py• L806-930 backend/…/resources_handler.py• L919-1067 backend/…/scan_handler.py• L480-489 backend/…/scan_handler.py• L531-648 backend/…/roms_handler.py• L1505-1519 backend/…/launchbox_handler.py• L7-15

User asset files

User asset files support saves, save states, screenshots, and memory card versions. They live in user-scoped areas outside the library ROM tree. Save, state, and screenshot paths include the user and normally the ROM, platform, and emulator. Memory card paths instead group versions by user, emulator, and card because one card can hold saves for many games.

Save and memory card content can use a content hash so repeated uploads can be recognized after a name change. ZIP content is hashed by entry name and entry content while streaming against a decompressed-size budget. A file is treated as an archive only when its archive starts at byte zero, so emulator state bytes that only end with ZIP data are hashed as one raw file. Uploaded save archives are checked before unpacking, so absolute paths, parent traversal, backslash paths, symlink entries, excessive entry counts, and oversized declared expansion are rejected. Uploaded images are checked from their bytes before acceptance. Trusted image types can render inline. Other asset types are served as downloads rather than rendered as pages.

References: backend/…/scan_handler.py• L686-780 backend/…/assets_handler.py• L40-143 backend/…/assets_handler.py• L166-305 backend/…/assets_handler.py• L315-383 backend/…/assets_handler.py• L386-480 backend/…/base_handler.py• L396-525 backend/…/base_handler.py• L640-733

RetroArch sync storage

RetroArch sync storage handles per-user files that are not owned by one ROM. It uses the same asset storage area as user assets but keeps emulator configuration, thumbnails, system files, and backup history in a separate namespace. ROM-owned saves and states still resolve through catalog records so sync clients can address them by ROM and emulator.

Blob files

Blob files are opaque files under a user and category path. A manifest scan lists regular files below each supported category, ignores temporary files left by interrupted writes, and returns paths relative to that category. The sync layer hashes the listed bytes and caches the result using the file size and modification time as the change key. This gives clients a compact view of files that do not map to catalog records while avoiding a full hash when the file has not changed.

References: backend/…/retroarch_sync_handler.py• L18-51 backend/…/retroarch_sync_handler.py• L94-121 backend/…/sync_handler.py• L785-913

Backup versions

Backup files preserve earlier versions of a ROM-owned or blob-owned file. A backup is stored under the user namespace and the source identity, then the newest configured number of sibling versions is retained. Publication uses a folder lock and whole-file replacement so concurrent sync requests do not publish partial bytes or prune the wrong version. If the source disappears before publication, the backup is not reported as created.

The sync endpoint derives ROM-owned backup paths from catalog records and keeps blob backups separate. It serves and writes these files through the filesystem handler rather than accepting a client path as a storage location.

References: backend/…/retroarch_sync_handler.py• L54-112 backend/…/sync_handler.py• L797-829 backend/…/retroarch.py• L413-438 backend/…/retroarch.py• L482-548

Filesystem safety

Filesystem handlers keep library and asset operations inside their assigned storage areas. They validate relative paths, reject unsafe names, serialize operations per path, and make replacement writes atomic so a cancelled scan or download does not leave a partial file that later discovery accepts. RetroArch backup publication adds a folder-level lock across worker processes and excludes interrupted temporary files from manifest discovery.

References: backend/…/base_handler.py• L383-480 backend/…/base_handler.py• L501-525 backend/…/base_handler.py• L640-733 backend/…/base_handler.py• L790-966 backend/…/retroarch_sync_handler.py• L30-91

Scan outputs

The scan reports platform, ROM, and firmware progress through task results and realtime events. These counts describe work in the current scan rather than the total contents of a platform, and frequent ROM updates are coalesced before they reach clients. After a successful scan, derived filters, smart collections, identity statistics, and similarity data are refreshed; a selected-ROM scan limits smart-collection work to the affected ROMs. Configured gamelist or Pegasus exports can then be written for the scanned platforms.

References: backend/…/scan.py• L201-290 backend/…/scan.py• L989-1013 backend/…/scan.py• L1394-1489 frontend/…/scanning.ts• L6-43

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep structure templates, platform discovery, and ROM path construction aligned. A path change in one pass can make another pass mark every record missing.
  • Keep exclusion rules consistent between ROM counting, ROM discovery, nested-part hashing, title-ID extraction, and archive members. Otherwise scan progress and reconciliation can disagree.
  • Preserve the full-location match before hash or title-ID recovery. A partial identity must not move a record to a new path.
  • Keep the hash and title-ID recovery rules aligned with the platforms that can provide each identity. Non-hashable platforms must not depend on empty hashes.
  • Keep title-ID readers and their source precedence aligned. A reader that fills a title ID must not erase a save target, version, or content type supplied by the other reader.
  • Keep filename tag parsing aligned with catalog facets. Compact numeric revision tags must remain distinct from ordinary words that start with Rev.
  • Keep optional Switch renaming after identity extraction and reconcile the renamed ROM path before persistence. A rename collision must leave the source record safe.
  • Preserve path-first and unique-content-second matching for ROM file rows. A file move should not become a delete and create new row IDs, and duplicate content must not be paired by guess.
  • Keep scanner-owned and stored-only ROM file fields separate. An absent scan value must not erase track or resource state that the scanner does not own.
  • Keep the per-ROM refresh lock and mount-loss guard with every ROM file refresh caller.
  • Keep physical records outside missing-state updates and missing-record cleanup.
  • Keep scene-source protection aligned with persisted scene IDs, provider errors, inconclusive lookups, and complete-scan clearing.
  • Keep title-ID extraction, optional Switch renaming, and ROM path updates in one contract.
  • Keep complete-scan source clearing and resource deletion aligned with the providers actually consulted. An inconclusive provider must not be treated as a confirmed miss.
  • Keep hash-source tag claims tied to their source metadata. A skipped source must not erase local tags or make an old dump claim look like this scan's answer.
  • Keep scan mode decisions aligned with the selected-ROM path. A database-scoped scan must not mark unrelated records present or missing.
  • Keep scan queue rules, stop-flag polling, and terminal failure events aligned. A selected-ROM scan must not trigger broad library reconciliation.
  • Keep firmware skip rules aligned with file replacement and hash verification. A same-size replacement can keep stale identity until a hash-focused scan.
  • Keep archive recognition consistent between save unpacking, save shape detection, and content hashing. Bytes that only contain a ZIP tail must remain raw in all three paths.
  • Keep scan counts, coalesced progress updates, and realtime event fields aligned with frontend scan state.
  • Keep local resource copies separate from source metadata files. A link in place of a copy can make a later resource rewrite change the source.
  • Keep resource path fields aligned with files that actually exist. Failed downloads and discarded placeholders must remain retryable from their source URLs.
  • Keep decoded media size limits and atomic replacement aligned. A gzip body must not bypass the size cap or replace a good file before decoding succeeds.
  • Keep provider media cleanup across all source records. Removing one source's old path must not delete a usable file still owned by another source.
  • Keep atomic writes and per-path locks in every filesystem write path. A cancelled or concurrent write must not leave a partial file that future scans accept.
  • Keep asset MIME validation, archive entry safety, decompressed-size budgets, and response disposition aligned. An accepted asset must not escape its storage folder, exhaust memory during hashing, or render as executable browser content.
  • Keep RetroArch blob categories, user namespaces, manifest paths, and hash-cache keys aligned. A path mismatch can hide a sync file or make a client hash the wrong object.
  • Keep temporary-file exclusion and folder-level backup locking in the sync storage path. Interrupted writes must not enter manifests, and concurrent backups must not prune each other's versions.
  • Keep ROM-owned backup resolution tied to catalog visibility while keeping blob backups independent of a ROM. A client path must not create an unscoped backup.

Important failure modes

TriggerConsequenceGuard
The library volume is not mounted or its configured structure is absentNo platforms or ROMs are found, and a broad scan can report existing records as missingRestore the mount and confirm the supported structure before scanning or cleaning up
A platform, file, or folder matches an exclusion ruleThe entry is invisible to discovery and can be marked missingCheck platform, single-file, multi-file, nested-part, and title-ID extraction exclusions
A custom structure overlaps another structure without the intended groupingA game can be discovered twice or its child files can be treated as a second gameReview template levels and keep grouping folders out of the terminal game level
Hashing is disabled or unavailable and no title ID existsA renamed or moved ROM cannot be safely recovered by contentKeep the old location or use a platform with a supported identity source
More than one missing ROM has the same complete hash or title IDThe scanner refuses to choose and can create a new recordRemove the ambiguity or match the record manually
Two ROM file rows have the same complete content keyA moved file cannot be safely paired with one old rowKeep path identity or resolve the duplicate before relying on content recovery
A nested archive cannot be readMember identity is unavailable and the archive may not match a hash databaseRepair or replace the archive; the scanner keeps a raw file identity
A file only ends with ZIP data but does not start with a ZIP archiveSave or memory-card content is treated as one raw file instead of as archive membersKeep archive detection consistent and do not classify an emulator state by its trailing bytes
A ROM file refresh sees an empty folder during a mount lossValid file rows can look deletedRestore the mount and rescan; the refresh protects stored rows from an empty transient result
Two refreshes run for one ROM at the same timeA slower listing can remove rows saved by the faster listingKeep per-ROM refresh serialization in place
A title-ID reader cannot inspect the file, an unreadable archive is used, or a sidecar is treated as a ROM binaryIdentity or content type can be missing or wrongKeep binary eligibility rules and the independent reader paths aligned
A Switch title-ID rename targets an existing fileThe source file is left unchanged and the catalog must keep its old pathResolve the name conflict before relying on embedded IDs
A firmware file is replaced without changing its size and a non-hash scan runsIts record can retain old hashes and verification stateRun a complete or hashes scan after replacing firmware
A complete scan omits a previously used metadata sourceIts source IDs and local resources can be clearedUse complete scans only when source removal and resource rebuild are intended
A complete scan consults a provider that does not answerA known source match can be mistaken for a confirmed missPreserve inconclusive provider state and retry with an unmatched scan
A scene provider is unavailable during a rescan of an identified productionA similar retail game can replace the production's title or artworkKeep persisted Demozoo, Pouët, and CSDb identity locked until a deliberate complete reset
A hash provider returns old dump tags after a local tag changeProvider tags can overwrite the local region or languageApply dump claims only to empty local fields and retain source ownership
A scan worker stops before it emits its terminal eventClients can show a dead scan as still runningKeep the job failure reporter and terminal-event marker in place
A running library scan is started again or a stop request clears the flag for another jobWork can overlap or a stopped scan can continueKeep broad scans queue-blocked and let the owning scan consume the stop flag
Missing-record cleanup runs after a temporary unmountMissing ROM records, resources, or firmware rows can be permanently removedRestore the library and scan before cleanup
A resource download returns the wrong media type, a partial or gzip body, or a placeholder imageThe bad file can block later resource refreshes or render as false artworkValidate content type, decode within the size cap, discard invalid resources, and retain the source URL for retry
A provider media path is removed without checking other provider recordsA usable shared resource can disappear even though another source still owns itCompare all old and new provider media before stale-file removal
An uploaded save archive contains traversal, absolute, backslash, or symlink entries, too many entries, or excessive declared expansionThe upload is unsafe to unpack and is rejectedValidate every archive entry and enforce entry-count and expansion limits before extraction
A ZIP asset expands beyond the actual decompressed hashing budgetHashing can fail instead of exhausting memoryStream entry hashing and enforce the whole-archive decompressed ceiling
An uploaded non-image is served with an inline browser typeUser-controlled content can execute or render as stored XSSSniff image bytes and serve non-image assets as opaque downloads
A caller supplies an absolute, parent-traversal, or unsafe file pathThe operation can escape its storage area or expose an unintended fileValidate relative paths against the assigned base and derive access from stored records
A write is cancelled or fails after the target is openedA partial file can pass existence checks and block later resource refreshesWrite beside the target and replace it only after the write completes
A sync blob is replaced without changing its size or modification timeThe manifest can reuse an old cached hashChange the file metadata or force the relevant sync hash cache to refresh
A backup source disappears during publicationThe backup is not created and the client receives a conflict instead of a successConfirm the source remains available and retry the backup operation
Concurrent backup publication does not hold the folder lockVersions can overwrite or prune each other incorrectlyKeep the process-wide and cross-worker folder lock around publication and retention
A temporary sync file is included in blob discoveryThe manifest can advertise incomplete or crash-left contentKeep temporary-file filtering in recursive blob listing

Key files

FileWhy to read it
backend/…/scan.pyDefines scan entry, authorization, queue control, scan modes, platform-wide and selected-ROM lifecycles, missing-state reconciliation, progress reporting, and post-scan work.
backend/…/scan_handler.pyDefines ROM identity recovery, metadata selection, provider failure handling, scene identity protection, hash-source tag handling, resource refresh, physical-game records, and scan-time asset handling.
backend/…/roms_handler.pyShows custom structure discovery, overlap handling, exclusions, file categories, archive members, incremental inspection, hashes, title-ID readers, filename tag parsing, optional Switch file renaming, and PICO-8 cover handling.
backend/…/base_handler.pyShows path safety, per-path locking, atomic writes, and link-or-copy behavior for library and resource files.
backend/…/assets_handler.pyShows user asset paths, archive recognition and content hashing, bounded archive content hashing, safe archive validation, image validation, and safe asset responses.
backend/…/launchbox_handler.pyProvides the isolated filesystem boundary for local LaunchBox source files used during metadata and resource import.
backend/…/retroarch_sync_handler.pyDefines the per-user filesystem boundary for opaque RetroArch sync files, manifest discovery, backup locking, whole-file publication, and version retention.
backend/…/sync_handler.pyMaps sync client paths to ROM-owned or blob-owned storage and builds the manifest from discovered files.
backend/…/retroarch.pyDefines the external sync contract for serving, uploading, and backing up ROM resources and opaque user files.
backend/…/__init__.pyShows the filesystem handler boundary and the separate handlers used for assets, ROMs, resources, firmware, and sync data.
backend/…/platforms_handler.pyShows platform-folder discovery, structure bootstrapping, and exclusion before directory access.
backend/…/firmware_handler.pyShows how platform firmware paths, file lists, and hashes are read.
backend/…/resources_handler.pyShows the boundary between source ROM files and downloaded or locally sourced catalog resources.
backend/…/roms_handler.pyShows missing-state updates, hash and title-ID recovery, and stable ROM file-row reconciliation.
backend/…/platforms_handler.pyShows how a missing platform propagates missing state to its file-backed ROMs.
backend/…/firmware_handler.pyShows firmware lookup, persistence, and missing-file marking.
backend/…/rom_files.pyCoordinates safe per-ROM file refreshes and protects rows during a transient mount failure.
backend/…/cleanup_missing_roms.pyDefines explicit cleanup of missing ROM records and their stored resources.
backend/…/cleanup_missing_firmware.pyDefines explicit cleanup of missing firmware records.
backend/…/scan_library.pyShows how scheduled rescans choose metadata sources and start quick scans.