Skip to content

fix: wipe downloaded resources on COMPLETE rescan#3406

Merged
gantoine merged 3 commits into
masterfrom
wipe-resources-complete-rescan
May 23, 2026
Merged

fix: wipe downloaded resources on COMPLETE rescan#3406
gantoine merged 3 commits into
masterfrom
wipe-resources-complete-rescan

Conversation

@gantoine
Copy link
Copy Markdown
Member

Problem

A COMPLETE rescan never deleted previously downloaded asset files, and the post-scan download steps short-circuit when work appears already done:

  • store_media_file always skips when the destination file exists (no overwrite param)
  • get_cover / get_manual / get_rom_screenshots only re-download when the source URL changed

So covers, screenshots, manuals, and SS/gamelist/LaunchBox extended media (miximage, bezel, box3d, logo, fanart, video, …) were reused even when a fresh fetch returned a different URL. This defeated the region-priority fix in #3396: the correct region couldn't replace an already-downloaded wrong-region cover/media because the old file was still on disk and path_cover_s still pointed at it.

Separately, when the sole provider of an artwork field was deselected, the on-disk file lingered and the url_* DB columns kept stale values (they're never seeded for COMPLETE, and the priority loops only set fields, never clear them).

Fix

  • endpoints/sockets/scan.py — for a COMPLETE rescan of an existing ROM, remove the cover, manual, screenshots, and every extended-media directory before re-fetching, so get_cover/store_media_file pull fresh files.
  • handler/scan_handler.py — reset url_cover/url_screenshots/url_manual and the matching path_* fields for COMPLETE rescans before the priority loops run. Stale DB values are now explicitly nulled when no selected source supplies them, rather than relying on session.merge semantics. Clearing for deselected sources falls out as a subset of this behavior.

Testing

DB_HOST=127.0.0.1 uv run pytest tests/endpoints/sockets/test_scan.py tests/handler/filesystem/test_resources_handler.py tests/handler/test_fastapi.py — 102 passed.

🤖 Generated with Claude Code

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) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 23, 2026 01:02
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2026

Test Results (mariadb)

    1 files  ±0      1 suites  ±0   4m 5s ⏱️ +21s
1 378 tests ±0  1 378 ✅ ±0  0 💤 ±0  0 ❌ ±0 
1 380 runs  ±0  1 380 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit da5675d. ± Comparison against base commit d7c789c.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
16485 11564 70% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
backend/endpoints/sockets/scan.py 23% 🟢
backend/handler/scan_handler.py 63% 🟢
TOTAL 43% 🟢

updated for commit: da5675d by action🐍

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes COMPLETE rescan behavior so previously downloaded artwork/media doesn’t get reused when metadata providers return updated URLs or when providers are deselected, ensuring “fresh” assets and clearing stale DB URL/path fields.

Changes:

  • Reset artwork URL/path fields during COMPLETE rescans so stale values get cleared when no selected source provides them.
  • Wipe on-disk downloaded artwork/media directories for existing ROMs during COMPLETE rescans to force re-fetching.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
backend/handler/scan_handler.py Clears artwork URL/path fields during COMPLETE rescans so stale values don’t persist when no provider supplies them.
backend/endpoints/sockets/scan.py Deletes existing on-disk artwork/media resources before COMPLETE rescans to prevent reuse of stale files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/endpoints/sockets/scan.py Outdated
Comment thread backend/endpoints/sockets/scan.py Outdated
Comment thread backend/endpoints/sockets/scan.py Outdated
Comment thread backend/handler/scan_handler.py Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2026

Test Results (postgresql)

    1 files  ±0      1 suites  ±0   3m 56s ⏱️ -4s
1 378 tests ±0  1 378 ✅ ±0  0 💤 ±0  0 ❌ ±0 
1 380 runs  ±0  1 380 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit da5675d. ± Comparison against base commit d7c789c.

♻️ This comment has been updated with latest results.

gantoine and others added 2 commits May 22, 2026 21:13
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@gantoine gantoine merged commit fa0b732 into master May 23, 2026
12 checks passed
@gantoine gantoine deleted the wipe-resources-complete-rescan branch May 23, 2026 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants