mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
A scan flags firmware whose file vanished, but nothing could act on the flag: stale BIOS entries could only be found by opening each platform's Firmware tab one at a time, the player still offered them (auto-selecting the sole entry, so the game failed to boot with nothing pointing at the BIOS), and platform firmware counts included them. Adds a `missing` filter to the firmware list endpoint, a `cleanup_missing_firmware` manual task alongside the ROM one, and a Missing firmware tab in Library management that lists every flagged entry library-wide with a bulk cleanup. The player now asks for present firmware only, and firmware selection moved to a `playerFirmware` util that never picks a missing entry. `firmware_count` counts only firmware present on disk; the rows themselves still ship so the Firmware tab can strike them through. `FirmwareSchema` gains `platform_id` so the library-wide list can group by platform. Fixes #4075 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
131 lines
3.8 KiB
Python
131 lines
3.8 KiB
Python
from collections.abc import Sequence
|
|
|
|
from sqlalchemy import and_, delete, select, update
|
|
from sqlalchemy.orm import QueryableAttribute, Session, load_only
|
|
|
|
from decorators.database import begin_session
|
|
from models.firmware import Firmware
|
|
|
|
from .base_handler import DBBaseHandler
|
|
|
|
|
|
class DBFirmwareHandler(DBBaseHandler):
|
|
@begin_session
|
|
def add_firmware(
|
|
self,
|
|
firmware: Firmware,
|
|
session: Session = None, # type: ignore
|
|
) -> Firmware:
|
|
return session.merge(firmware)
|
|
|
|
@begin_session
|
|
def get_firmware(
|
|
self,
|
|
id: int,
|
|
*,
|
|
session: Session = None, # type: ignore
|
|
) -> Firmware | None:
|
|
return session.scalar(select(Firmware).filter_by(id=id).limit(1))
|
|
|
|
@begin_session
|
|
def list_firmware(
|
|
self,
|
|
*,
|
|
platform_id: int | None = None,
|
|
missing: bool | None = None,
|
|
only_fields: Sequence[QueryableAttribute] | None = None,
|
|
hidden_platform_ids: Sequence[int] | None = None,
|
|
session: Session = None, # type: ignore
|
|
) -> Sequence[Firmware]:
|
|
query = select(Firmware).order_by(Firmware.file_name.asc())
|
|
|
|
if platform_id:
|
|
query = query.filter_by(platform_id=platform_id)
|
|
|
|
if missing is not None:
|
|
query = query.filter(Firmware.missing_from_fs == missing)
|
|
|
|
# Firmware inherits its platform's visibility: hide firmware whose
|
|
# platform an admin has hidden from the caller.
|
|
if hidden_platform_ids:
|
|
query = query.filter(Firmware.platform_id.not_in(hidden_platform_ids))
|
|
|
|
if only_fields:
|
|
query = query.options(load_only(*only_fields))
|
|
|
|
return session.scalars(query).all()
|
|
|
|
@begin_session
|
|
def get_firmware_by_filename(
|
|
self,
|
|
platform_id: int,
|
|
file_name: str,
|
|
session: Session = None, # type: ignore
|
|
):
|
|
return session.scalar(
|
|
select(Firmware)
|
|
.filter_by(platform_id=platform_id, file_name=file_name)
|
|
.limit(1)
|
|
)
|
|
|
|
@begin_session
|
|
def update_firmware(
|
|
self,
|
|
id: int,
|
|
data: dict,
|
|
session: Session = None, # type: ignore
|
|
) -> Firmware:
|
|
session.execute(
|
|
update(Firmware)
|
|
.where(Firmware.id == id)
|
|
.values(**data)
|
|
.execution_options(synchronize_session="evaluate")
|
|
)
|
|
return session.query(Firmware).filter_by(id=id).one()
|
|
|
|
@begin_session
|
|
def delete_firmware(
|
|
self,
|
|
id: int,
|
|
session: Session = None, # type: ignore
|
|
) -> None:
|
|
session.execute(
|
|
delete(Firmware)
|
|
.where(Firmware.id == id)
|
|
.execution_options(synchronize_session="evaluate")
|
|
)
|
|
|
|
@begin_session
|
|
def mark_missing_firmware(
|
|
self,
|
|
platform_id: int,
|
|
fs_firmwares_to_keep: list[str],
|
|
session: Session = None, # type: ignore
|
|
) -> Sequence[Firmware]:
|
|
missing_firmware = (
|
|
session.scalars(
|
|
select(Firmware)
|
|
.order_by(Firmware.file_name.asc())
|
|
.where(
|
|
and_(
|
|
Firmware.platform_id == platform_id,
|
|
Firmware.file_name.not_in(fs_firmwares_to_keep),
|
|
)
|
|
)
|
|
) # type: ignore[attr-defined]
|
|
.unique()
|
|
.all()
|
|
)
|
|
session.execute(
|
|
update(Firmware)
|
|
.where(
|
|
and_(
|
|
Firmware.platform_id == platform_id,
|
|
Firmware.file_name.not_in(fs_firmwares_to_keep),
|
|
)
|
|
)
|
|
.values(**{"missing_from_fs": True})
|
|
.execution_options(synchronize_session="evaluate")
|
|
)
|
|
return missing_firmware
|