From a5ed1d95eafe3867eb5c7753221d22682e84c894 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Fri, 22 May 2026 17:32:02 -0400 Subject: [PATCH 1/3] fix: wipe downloaded resources on COMPLETE rescan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A COMPLETE rescan never deleted previously downloaded asset files, and the post-scan download steps skip work when a file already exists (store_media_file) or when the source URL is unchanged (get_cover). This meant covers, screenshots, manuals, and SS/gamelist/LaunchBox extended media were reused even when a fresh fetch returned a different URL — defeating the region-priority fix in #3396. - scan socket: for a COMPLETE rescan of an existing ROM, remove the cover, manual, screenshots, and all extended media directories before re-fetching, so the download steps pull fresh files. - scan_handler: reset url_cover/url_screenshots/url_manual and the matching path_* fields for COMPLETE rescans before the priority loops run, so stale DB values are nulled when no selected source supplies them (clearing for deselected sources falls out as a subset). Co-Authored-By: Claude Opus 4.7 (1M context) --- backend/endpoints/sockets/scan.py | 16 ++++++++++++++++ backend/handler/scan_handler.py | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/backend/endpoints/sockets/scan.py b/backend/endpoints/sockets/scan.py index f2d490436..6636e8471 100644 --- a/backend/endpoints/sockets/scan.py +++ b/backend/endpoints/sockets/scan.py @@ -11,6 +11,7 @@ from rq import Worker from rq.job import Job from config import DEV_MODE, REDIS_URL, SCAN_TIMEOUT, SCAN_WORKERS, TASK_RESULT_TTL +from config.config_manager import MetadataMediaType from config.config_manager import config_manager as cm from endpoints.responses import TaskType from endpoints.responses.platform import PlatformSchema @@ -295,6 +296,21 @@ async def _identify_rom( } ) + # For a COMPLETE rescan, wipe all downloaded resources before re-fetching so + # stale files (e.g. a cover from the wrong region) can't be reused. The + # post-scan download steps below skip downloads when a file already exists or + # when the source URL is unchanged, so the on-disk files must be removed here. + if not newly_added and scan_type == ScanType.COMPLETE: + await fs_resource_handler.remove_cover(rom) + await fs_resource_handler.remove_manual(rom) + await fs_resource_handler.remove_directory( + f"{rom.fs_resources_path}/screenshots" + ) + for media_type in MetadataMediaType: + await fs_resource_handler.remove_media_resources_path( + platform.id, rom.id, media_type + ) + log.debug(f"Scanning {rom.fs_name}...") scanned_rom = await scan_rom( scan_type=scan_type, diff --git a/backend/handler/scan_handler.py b/backend/handler/scan_handler.py index 2f39b334c..fb6d77ec5 100644 --- a/backend/handler/scan_handler.py +++ b/backend/handler/scan_handler.py @@ -888,6 +888,19 @@ async def scan_rom( if fields["metadata_field"]: rom_attrs[fields["metadata_field"]] = {} + # Reset artwork fields so stale values are nulled when no source supplies them + rom_attrs.update( + { + "url_cover": None, + "url_screenshots": [], + "url_manual": None, + "path_cover_s": None, + "path_cover_l": None, + "path_screenshots": [], + "path_manual": None, + } + ) + # Determine which metadata sources are available available_sources = [ name From c73899a8847e5c1ddf89385d13c33e836ca2bb6f Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi <3247106+gantoine@users.noreply.github.com> Date: Fri, 22 May 2026 21:13:22 -0400 Subject: [PATCH 2/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- backend/endpoints/sockets/scan.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/backend/endpoints/sockets/scan.py b/backend/endpoints/sockets/scan.py index 6636e8471..5ad8cc93a 100644 --- a/backend/endpoints/sockets/scan.py +++ b/backend/endpoints/sockets/scan.py @@ -301,15 +301,30 @@ async def _identify_rom( # post-scan download steps below skip downloads when a file already exists or # when the source URL is unchanged, so the on-disk files must be removed here. if not newly_added and scan_type == ScanType.COMPLETE: - await fs_resource_handler.remove_cover(rom) - await fs_resource_handler.remove_manual(rom) - await fs_resource_handler.remove_directory( - f"{rom.fs_resources_path}/screenshots" - ) - for media_type in MetadataMediaType: - await fs_resource_handler.remove_media_resources_path( - platform.id, rom.id, media_type + try: + await fs_resource_handler.remove_cover(rom) + except FileNotFoundError: + pass + + try: + await fs_resource_handler.remove_manual(rom) + except FileNotFoundError: + pass + + try: + await fs_resource_handler.remove_directory( + f"{rom.fs_resources_path}/screenshots" ) + except FileNotFoundError: + pass + + for media_type in MetadataMediaType: + try: + await fs_resource_handler.remove_media_resources_path( + platform.id, rom.id, media_type + ) + except FileNotFoundError: + pass log.debug(f"Scanning {rom.fs_name}...") scanned_rom = await scan_rom( From da5675dca5dca5b90f2772cb591785a35a4e55ba Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi <3247106+gantoine@users.noreply.github.com> Date: Fri, 22 May 2026 21:14:16 -0400 Subject: [PATCH 3/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- backend/handler/scan_handler.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/handler/scan_handler.py b/backend/handler/scan_handler.py index fb6d77ec5..6cd524f17 100644 --- a/backend/handler/scan_handler.py +++ b/backend/handler/scan_handler.py @@ -888,16 +888,16 @@ async def scan_rom( if fields["metadata_field"]: rom_attrs[fields["metadata_field"]] = {} - # Reset artwork fields so stale values are nulled when no source supplies them + # Reset artwork fields so stale values are cleared when no source supplies them rom_attrs.update( { - "url_cover": None, + "url_cover": "", "url_screenshots": [], - "url_manual": None, - "path_cover_s": None, - "path_cover_l": None, + "url_manual": "", + "path_cover_s": "", + "path_cover_l": "", "path_screenshots": [], - "path_manual": None, + "path_manual": "", } )