Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions backend/endpoints/sockets/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions backend/handler/scan_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading