From 7e8be36ea60998e0c41c8d5aa48df19afb9f2aa9 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Tue, 21 Jul 2026 08:09:40 -0400 Subject: [PATCH] cleanup --- backend/endpoints/sockets/scan.py | 17 +++++++++-------- backend/handler/database/roms_handler.py | 8 ++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/backend/endpoints/sockets/scan.py b/backend/endpoints/sockets/scan.py index ceba2fad7..9e2fa778e 100644 --- a/backend/endpoints/sockets/scan.py +++ b/backend/endpoints/sockets/scan.py @@ -287,20 +287,23 @@ async def _identify_rom( "url_screenshots": [], } + calculate_hashes = not cm.get_config().SKIP_HASH_CALCULATION + newly_added: bool = rom is None reassociated: bool = False files_built: bool = False if rom is None: - # No entry matches this filename. Before treating it as brand new, hash + # No entry matches this filename. Before treating it as new, hash # the files and check whether they belong to an existing entry that went # missing (a renamed or moved ROM), so its collections, notes, and # uploaded assets carry over instead of being orphaned on a duplicate. - calculate_hashes = not cm.get_config().SKIP_HASH_CALCULATION - candidate = Rom(**rom_attrs) - candidate.platform = platform parsed_rom_files = await fs_rom_handler.get_rom_files( - candidate, calculate_hashes=calculate_hashes + Rom( + **rom_attrs, + platform=platform, + ), + calculate_hashes=calculate_hashes, ) fs_rom.update( { @@ -320,8 +323,7 @@ async def _identify_rom( sha1_hash=parsed_rom_files.sha1_hash, ) if missing_match is not None: - # Move the existing entry onto the new file, clearing its missing - # state. User data (collections, notes, assets) stays linked by id. + # Move the existing entry onto the new file, clearing its missing state. rom = db_rom_handler.update_rom( missing_match.id, { @@ -361,7 +363,6 @@ async def _identify_rom( ) if should_update_files and not files_built: # Get hash calculation setting from config - calculate_hashes = not cm.get_config().SKIP_HASH_CALCULATION if calculate_hashes: log.debug(f"Calculating file hashes for {rom.fs_name}...") diff --git a/backend/handler/database/roms_handler.py b/backend/handler/database/roms_handler.py index a01d7122d..181d5a19e 100644 --- a/backend/handler/database/roms_handler.py +++ b/backend/handler/database/roms_handler.py @@ -2235,13 +2235,8 @@ class DBRomsHandler(DBBaseHandler): Used during scanning to reassociate a renamed or moved file with its existing entry (preserving collections, notes, and assets) instead of creating a duplicate. Requires the CRC, MD5, and SHA1 hashes to all - match, so a lone CRC32 collision can't move an unrelated entry onto the - file. Any missing hash yields no match, so non-hashable platforms and + match. Any missing hash yields no match, so non-hashable platforms and pre-hash entries safely fall back to creating a new entry. - - Returns None when more than one missing entry matches: an ambiguous set - (e.g. duplicate content stored twice) has no correct target, so we - create a new entry rather than move user data onto an arbitrary row. """ if not (crc_hash and md5_hash and sha1_hash): return None @@ -2260,6 +2255,7 @@ class DBRomsHandler(DBBaseHandler): .limit(2) ).all() + # Return None when more than one match to avoid ambiguity. return matches[0] if len(matches) == 1 else None def _collect_filter_values(