mirror of
https://github.com/rommapp/romm.git
synced 2026-12-05 05:07:31 +01:00
fix: allow ROM deletion when file is missing
Co-authored-by: zurdi15 <34356590+zurdi15@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
bd2e6b7962
commit
bd0bc65e92
@@ -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"
|
||||
|
||||
@@ -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
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user