fix: compare redump datfiles by their file stamp

This commit is contained in:
Abdessamad Derraz committed 2026-11-22 02:26:44 +01:00
1 parent 80461985d3
commit 768ac05b4d
3 files changed
+56 -10

No files matched your search

+8 -5
View File
@@ -111,18 +111,21 @@ def redump_datfile_version(code: str) -> str:
disposition = upstream.open_retrying(
request, lambda response: response.headers.get("Content-Disposition", ""), timeout=60
)
named = game_dat_importer.DISPOSITION.search(disposition)
match = game_dat_importer.REDUMP_FILE.match(named["file"]) if named else None
if not match:
version = game_dat_importer.served_version(game_dat_importer.datfile_name(disposition) or "")
if not version:
raise ValueError(f"{url} names no datfile")
return f"{match['date']} {match['time']}"
return version
def _check_redump_games(offline: bool) -> Finding:
"""games/catalogs/redump/ against the datfiles redump.info serves now.
A disc dumped since is not recognised by the games-on-card mode."""
subject = REDUMP_GAMES
local = {doc.get("system"): str(doc.get("version", "")) for doc in _game_catalogs("redump")}
# The stamp of the file the import read, the one the server names now.
local = {
doc.get("system"): game_dat_importer.served_version(str((doc.get("archive") or {}).get("file", "")))
for doc in _game_catalogs("redump")
}
newest = max(local.values(), default="")
if offline:
return Finding("catalogs", subject, SKIPPED, local=newest, detail="offline")
+19 -3
View File
@@ -167,6 +167,22 @@ REDUMP_FILE = re.compile(
)
def datfile_name(disposition: str) -> str | None:
"""The file name a redump.info Content-Disposition header gives a datfile."""
match = DISPOSITION.search(disposition)
return match["file"] if match else None
def served_version(file: str) -> str:
"""The version redump.info stamps in a datfile name, empty for another name.
The import records the name, and the freshness check reads the name the
server gives now: both sides compare this stamp, never the DAT header.
"""
match = REDUMP_FILE.match(file)
return f"{match['date']} {match['time']}" if match else ""
def name_regions(name: str) -> list[str] | None:
"""Region slugs of the first parenthesised group made only of territory
words, or None when the name carries no such group or a word the
@@ -299,10 +315,10 @@ def fetch_redump(code: str, cache_dir: Path, offline: bool, refresh: bool) -> tu
if offline:
raise NotCachedError(f"{pack} is not cached")
url = REDUMP_DATFILE_URL.format(code=code)
match = DISPOSITION.search(download(url, pack))
if not match:
file = datfile_name(download(url, pack))
if not file:
raise RuntimeError(f"{url} answered without a datfile name")
meta = {"file": match["file"], "url": url, "fetched": _today()}
meta = {"file": file, "url": url, "fetched": _today()}
write_text_atomic(str(meta_path), json.dumps(meta, indent=1) + "\n")
return pack, meta