fix: allow ROM deletion when file is missing

Co-authored-by: zurdi15 <34356590+zurdi15@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-06-20 16:23:24 +00:00
committed by GitHub
parent bd2e6b7962
commit bd0bc65e92
2 changed files with 29 additions and 5 deletions

View File

@@ -1641,11 +1641,9 @@ async def delete_roms(
f"Couldn't clean up empty parent directory for {hl(rom.fs_name)}: {dir_err}"
)
except FileNotFoundError:
error = f"Rom file {hl(rom.fs_name)} not found for platform {hl(rom.platform_display_name, color=BLUE)}[{hl(rom.platform_slug)}]"
log.error(error)
errors.append(error)
failed_items += 1
continue
log.warning(
f"Rom file {hl(rom.fs_name)} not found for platform {hl(rom.platform_display_name, color=BLUE)}[{hl(rom.platform_slug)}], deleting database entry only"
)
log.info(
f"Deleting {hl(str(rom.name or 'ROM'), color=BLUE)} [{hl(rom.fs_name)}] from database"

View File

@@ -461,6 +461,32 @@ def test_delete_roms_from_fs_nested(
mock_remove_directory.assert_called_once()
@patch("endpoints.roms.fs_rom_handler.validate_path")
def test_delete_roms_from_fs_missing_file_still_deletes_db_entry(
mock_validate_path,
client: TestClient,
access_token: str,
rom: Rom,
):
"""Test that missing ROM files do not block database deletion."""
from handler.database import db_rom_handler
mock_validate_path.side_effect = FileNotFoundError
response = client.post(
"/api/roms/delete",
headers={"Authorization": "Bearer " + access_token},
json={"roms": [rom.id], "delete_from_fs": [rom.id]},
)
assert response.status_code == status.HTTP_200_OK
body = response.json()
assert body["successful_items"] == 1
assert body["failed_items"] == 0
assert body["errors"] == []
assert db_rom_handler.get_rom(rom.id) is None
def test_update_rom_user_props_flat_payload(
client: TestClient, access_token: str, rom: Rom
):