diff --git a/backend/endpoints/sockets/scan.py b/backend/endpoints/sockets/scan.py index f2d490436..5ad8cc93a 100644 --- a/backend/endpoints/sockets/scan.py +++ b/backend/endpoints/sockets/scan.py @@ -11,6 +11,7 @@ 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,36 @@ 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: + 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( scan_type=scan_type, diff --git a/backend/handler/scan_handler.py b/backend/handler/scan_handler.py index 2f39b334c..6cd524f17 100644 --- a/backend/handler/scan_handler.py +++ b/backend/handler/scan_handler.py @@ -888,6 +888,19 @@ async def fetch_hasheous_rom(hasheous_rom: HasheousRom) -> HasheousRom: if fields["metadata_field"]: rom_attrs[fields["metadata_field"]] = {} + # Reset artwork fields so stale values are cleared when no source supplies them + rom_attrs.update( + { + "url_cover": "", + "url_screenshots": [], + "url_manual": "", + "path_cover_s": "", + "path_cover_l": "", + "path_screenshots": [], + "path_manual": "", + } + ) + # Determine which metadata sources are available available_sources = [ name