diff --git a/install.ps1 b/install.ps1 index 91f86e991..c4f8eda23 100644 --- a/install.ps1 +++ b/install.ps1 @@ -16,7 +16,7 @@ # and Invoke-WebRequest throws on a cut transfer before the hash is read: # the site's build rewrites this line there (scripts/sitebootstrap.py). $mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." - $defaultInstallSha256 = "86fed4f666cfb7398dbc57b285c2f493c6abb30da394a639d765162001cd0eae" + $defaultInstallSha256 = "3663191134988402971a3d0ae0860d6fbf158496ca03a41ff11efa4dd7a1a25b" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. $maximumInstallerBytes = 8MB diff --git a/install.py b/install.py index 8a19d8969..d72cd25e3 100644 --- a/install.py +++ b/install.py @@ -3447,8 +3447,9 @@ def _check_data_directory(entry: object, where: str) -> None: values = entry.get(field, []) if not isinstance(values, list) or not all(isinstance(v, str) for v in values): raise ValueError(f"{where}.{field} is invalid") - if entry.get("optional", True) is not True: - raise ValueError(f"{where}.optional is invalid") + for flag in ("optional", "rolling"): + if entry.get(flag, True) is not True: + raise ValueError(f"{where}.{flag} is invalid") cores = entry.get("cores", ["-"]) if not isinstance(cores, list) or not cores or not all(isinstance(c, str) and c for c in cores): raise ValueError(f"{where}.cores is invalid") @@ -9754,6 +9755,17 @@ def record_file(entry: dict, origin: str, root: str = "") -> dict: "from": origin} +def recorded_data_copies(folder: Path) -> dict[str, set[tuple[str, int]]]: + """The data tree files earlier runs wrote in folder, as its record names + them: (sha1, size) of each, by destination casefolded.""" + copies: dict[str, set[tuple[str, int]]] = {} + for setup in ((load_record(folder).data or {}).get("setups") or {}).values(): + for item in setup.get("files") or []: + if str(item.get("root") or "") == "data": + copies.setdefault(item["dest"].casefold(), set()).add((item["sha1"], item["size"])) + return copies + + def write_record( folder: Path, plat: str, manifest: dict, choice: list[str], files: list[dict], ) -> tuple[Path | None, dict, str]: @@ -16902,18 +16914,30 @@ def _archive_members( yield rel, member.size, functools.partial(_tar_member, tf, member) +def _slot(entry: dict, rel: str) -> str: + """A tree member's place below the BIOS folder, as the record names it.""" + return f"{entry['dest']}/{rel}" if entry.get("dest") else rel + + def data_directory_state(entry: dict, bios_path: Path, remember: bool = False) -> tuple[Path, dict[str, dict], int]: """(tree root, files missing or wrong, files already right). remember - keeps what was read for the check after the line menu (_HEAD_READS).""" + keeps what was read for the check after the line menu (_HEAD_READS). + + A rolling tree's file is right as the list hashes it or as an earlier + run wrote it from the source (the install record): the source has moved + on from the pack's copy, and that file is the newer one.""" root = _destination_path(bios_path, entry["dest"]) if entry.get("dest") else bios_path.resolve() needed: dict[str, dict] = {} present = 0 + written = recorded_data_copies(bios_path) if entry.get("rolling") else {} for rel, meta in entry["files"].items(): target = _destination_path(root, rel) + accepted = {(meta["sha1"], meta["size"])} | written.get(_slot(entry, rel).casefold(), set()) try: - held = (target.is_file() and target.stat().st_size == meta["size"] - and _read_digests(target, ("sha1",), remember)["sha1"] == meta["sha1"]) + size = target.stat().st_size if target.is_file() else -1 + held = (any(size == known for _sha1, known in accepted) + and (_read_digests(target, ("sha1",), remember)["sha1"], size) in accepted) except OSError: held = False if held: @@ -16959,8 +16983,17 @@ def install_data_directory(entry: dict, bios_path: Path, state is the tree's data_directory_state when the run already read it: each read hashes every file in place. - Returns counts: present, installed, changed (the source no longer holds - the recorded bytes), absent (not in the archive), error, the reason + A rolling tree (a source that names no revision, the buildbot's nightly + assets) is written as its source serves it now, as RetroArch's own + downloader writes it: a member whose bytes differ from the list is + written all the same, read to the size its archive declares and, in a + ZIP, checked against its CRC-32. A tree listed at a commit keeps only + the listed bytes. + + Returns counts: present, installed, updated (of those installed, the + ones a rolling source holds newer than the list), changed (the source + no longer holds the recorded bytes), absent (not in the archive), error, + the reason the archive could not be read, not_kept, the (path, reason) of each file in place that differs and could not be moved aside, left as it is, and written, each file written (dest below the BIOS folder, sha1, size). @@ -16969,9 +17002,11 @@ def install_data_directory(entry: dict, bios_path: Path, needed = dict(needed) written: list[dict] = [] not_kept: list[tuple[str, str]] = [] - tallies = {"installed": 0, "changed": 0} + tallies = {"installed": 0, "updated": 0, "changed": 0} + # From a pack, the pack's copy is the tree: nothing newer to follow. + rolling = bool(entry.get("rolling")) and LOCAL.pack is None counts: dict[str, object] = { - "present": present, "installed": 0, "changed": 0, "absent": 0, "error": "", + "present": present, "installed": 0, "updated": 0, "changed": 0, "absent": 0, "error": "", "not_kept": not_kept, "written": written} if not needed: return counts @@ -17004,19 +17039,24 @@ def install_data_directory(entry: dict, bios_path: Path, # Read no more than the list records: the archive's own size # field is checked first, and the stream is cut at the # expected size whatever the member claims, so a member that - # inflates without end costs one byte past it. - if declared != meta["size"]: + # inflates without end costs one byte past it. A rolling + # source's member is cut at the size its archive declares. + if declared != meta["size"] and not (rolling and 0 <= declared <= MAX_DOWNLOAD_SIZE): tallies["changed"] += 1 continue target = _destination_path(root, rel) target.parent.mkdir(parents=True, exist_ok=True) - slot = f"{entry['dest']}/{rel}" if entry.get("dest") else rel - outcome = _install_data_member( - opener, meta, target, bios_path, slot, rel, not_kept) + slot = _slot(entry, rel) + outcome, landed = _install_data_member( + opener, meta, target, bios_path, slot, rel, not_kept, + declared if rolling else None) if outcome: tallies[outcome] += 1 - if outcome == "installed": - written.append({"dest": slot, "sha1": meta["sha1"], "size": meta["size"]}) + if outcome == "updated": + # Installed too: updated counts the newer ones among them. + tallies["installed"] += 1 + if landed is not None: + written.append({"dest": slot, **landed}) except _Offline as exc: # Kept apart, so the advice is the offline one, not the network's. counts["error"] = OfflineReason(str(exc)) @@ -17040,6 +17080,7 @@ def install_data_directory(entry: dict, bios_path: Path, if lock is not None: _release_claim(lock, lock_path) counts["installed"] = tallies["installed"] + counts["updated"] = tallies["updated"] counts["changed"] = tallies["changed"] counts["absent"] = len(needed) return counts @@ -17048,11 +17089,17 @@ def install_data_directory(entry: dict, bios_path: Path, def _install_data_member( opener: Callable[[], ContextManager[IO[bytes]]], meta: dict, target: Path, bios_path: Path, slot: str, rel: str, not_kept: list[tuple[str, str]], -) -> str: + follow: int | None = None, +) -> tuple[str, dict | None]: """Write one member of a data tree's archive at target once its bytes - are the recorded ones: "installed", "changed" when they are not, or "" - when the file in place could not be moved aside (named in not_kept). + are the recorded ones: ("installed", what landed), ("changed", None) + when they are not, or ("", None) when the file in place could not be + moved aside (named in not_kept). follow is the size a rolling source's + archive declares for the member: its bytes land whatever they hash to, + ("updated", what landed) when they are not the listed ones, and a + stream that ends short of that size or runs past it is "changed". A read or write error is raised, and leaves no .part behind.""" + expected = meta["size"] if follow is None else follow scratch: Path | None = None try: digest = hashlib.sha1() @@ -17061,23 +17108,27 @@ def _install_data_member( dir=target.parent, prefix=f".{target.name}.", suffix=".part", delete=False, ) as out: scratch = Path(out.name) - while size <= meta["size"]: - chunk = src.read(min(1024 * 1024, meta["size"] + 1 - size)) + # Read to the end, one byte past at most: a ZIP member checks + # its CRC-32 when its stream ends, and raises when it differs. + while size <= expected: + chunk = src.read(min(1024 * 1024, expected + 1 - size)) if not chunk: break digest.update(chunk) size += len(chunk) out.write(chunk) - if digest.hexdigest() != meta["sha1"] or size != meta["size"]: - return "changed" + sha1 = digest.hexdigest() + listed = sha1 == meta["sha1"] and size == meta["size"] + if size != expected or not (listed or follow is not None): + return "changed", None try: - KEPT.keep(*_kept_slot(bios_path, slot), target, {"sha1": meta["sha1"]}) + KEPT.keep(*_kept_slot(bios_path, slot), target, {"sha1": sha1}) except _NotKept as exc: not_kept.append((rel, str(exc))) - return "" + return "", None os.replace(scratch, target) scratch = None - return "installed" + return ("installed" if listed else "updated"), {"sha1": sha1, "size": size} finally: if scratch is not None: scratch.unlink(missing_ok=True) @@ -19188,7 +19239,9 @@ def _fill_pack(args: argparse.Namespace, pack: _PackFill, staging: Path, if not owned: continue detail(f" {entry.get('ref', 'data')}: {_plural(len(names), 'data file')}...") - counts = install_data_directory(entry, root) + # The pack is rebuilt byte for byte: its tree is the listed one, + # never what a rolling source serves since. + counts = install_data_directory({**entry, "rolling": False}, root) problem = (str(counts["error"]) if counts["error"] else f"{counts['changed']} changed in its source" if counts["changed"] else f"{counts['absent']} not in its source" if counts["absent"] @@ -23311,6 +23364,9 @@ def _pass_install_tree(run: _InstallRun, p: _PlatformPass, entry: dict, # said so of 218 files no source was asked for. line = f" {entry['ref']}: {counts['installed']} installed, " \ f"{counts['present']} already in place" + if counts["updated"]: + # A rolling source moved on since the list: its bytes landed. + line += f", {counts['updated']} newer than the pack's (as {entry['url']} serves them)" if counts["changed"] or counts["absent"]: # From a pack, the pack is the source that lacks them. line += (f", {counts['changed'] + counts['absent']} not in " diff --git a/install.sh b/install.sh index 31ba67d4c..764f83e1d 100755 --- a/install.sh +++ b/install.sh @@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins # curl or wget stop on a cut transfer before the hash is read: the site's # build rewrites this line there (scripts/sitebootstrap.py). MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." -DEFAULT_INSTALL_SHA256="86fed4f666cfb7398dbc57b285c2f493c6abb30da394a639d765162001cd0eae" +DEFAULT_INSTALL_SHA256="3663191134988402971a3d0ae0860d6fbf158496ca03a41ff11efa4dd7a1a25b" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. MAX_INSTALLER_BYTES=8388608 diff --git a/install/amberelec.json b/install/amberelec.json index 85bcc7c31..90c50795f 100644 --- a/install/amberelec.json +++ b/install/amberelec.json @@ -74496,6 +74496,7 @@ }, "strip_components": 0, "archive_size": 4465709, + "rolling": true, "cores": [ "bluemsx" ] @@ -74503,7 +74504,7 @@ { "ref": "fbneo-cheats", "dest": "bios/fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [ "nec-pc-engine" @@ -88203,7 +88204,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -88415,6 +88416,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" @@ -88423,7 +88425,7 @@ { "ref": "freeintv-overlays", "dest": "bios/freeintv_overlays", - "url": "https://github.com/libretro/FreeIntv/raw/master/Assets/Overlays.zip", + "url": "https://github.com/libretro/FreeIntv/raw/ef3e0fe322bec62a7f916c0bb0834c08c348d0b4/Assets/Overlays.zip", "type": "zip", "systems": [ "mattel-intellivision" diff --git a/install/batocera.json b/install/batocera.json index 87037f6df..4e132aade 100644 --- a/install/batocera.json +++ b/install/batocera.json @@ -259591,6 +259591,7 @@ }, "strip_components": 0, "archive_size": 5752250, + "rolling": true, "cores": [ "dinothawr" ] @@ -259649,6 +259650,7 @@ }, "strip_components": 0, "archive_size": 175384, + "rolling": true, "cores": [ "dirksimple" ] @@ -259656,7 +259658,7 @@ { "ref": "fbneo-cheats", "dest": "fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [ "nec-pc-engine" @@ -273356,7 +273358,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -273568,6 +273570,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" diff --git a/install/emudeck.json b/install/emudeck.json index ad22ca0db..d483ed290 100644 --- a/install/emudeck.json +++ b/install/emudeck.json @@ -149078,6 +149078,7 @@ }, "strip_components": 0, "archive_size": 4465709, + "rolling": true, "cores": [ "bluemsx" ] @@ -149528,6 +149529,7 @@ }, "strip_components": 0, "archive_size": 5752250, + "rolling": true, "cores": [ "dinothawr" ] @@ -149586,6 +149588,7 @@ }, "strip_components": 0, "archive_size": 175384, + "rolling": true, "cores": [ "dirksimple" ] @@ -158265,6 +158268,7 @@ "Themes" ], "archive_size": 3197914, + "rolling": true, "cores": [ "ishiiruka" ] @@ -158272,7 +158276,7 @@ { "ref": "fbneo-cheats", "dest": "fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [ "nintendo-nes" @@ -171972,7 +171976,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -172184,6 +172188,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" @@ -172192,7 +172197,7 @@ { "ref": "freeintv-overlays", "dest": "freeintv_overlays", - "url": "https://github.com/libretro/FreeIntv/raw/master/Assets/Overlays.zip", + "url": "https://github.com/libretro/FreeIntv/raw/ef3e0fe322bec62a7f916c0bb0834c08c348d0b4/Assets/Overlays.zip", "type": "zip", "systems": [], "files": { @@ -172580,6 +172585,7 @@ }, "strip_components": 0, "archive_size": 318896, + "rolling": true, "cores": [ "lrps2" ] diff --git a/install/emuelec.json b/install/emuelec.json index ebc55283e..c0af54d40 100644 --- a/install/emuelec.json +++ b/install/emuelec.json @@ -76563,6 +76563,7 @@ }, "strip_components": 0, "archive_size": 4465709, + "rolling": true, "cores": [ "bluemsx" ] @@ -77015,6 +77016,7 @@ }, "strip_components": 0, "archive_size": 5752250, + "rolling": true, "cores": [ "dinothawr" ] @@ -77022,7 +77024,7 @@ { "ref": "fbneo-cheats", "dest": "bios/fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [ "nec-pc-engine" @@ -90722,7 +90724,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -90934,6 +90936,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" @@ -90942,7 +90945,7 @@ { "ref": "freeintv-overlays", "dest": "bios/freeintv_overlays", - "url": "https://github.com/libretro/FreeIntv/raw/master/Assets/Overlays.zip", + "url": "https://github.com/libretro/FreeIntv/raw/ef3e0fe322bec62a7f916c0bb0834c08c348d0b4/Assets/Overlays.zip", "type": "zip", "systems": [ "mattel-intellivision" diff --git a/install/knulli.json b/install/knulli.json index a2b333006..5545c9137 100644 --- a/install/knulli.json +++ b/install/knulli.json @@ -162563,6 +162563,7 @@ }, "strip_components": 0, "archive_size": 5752250, + "rolling": true, "cores": [ "dinothawr" ] @@ -162570,7 +162571,7 @@ { "ref": "fbneo-cheats", "dest": "fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [ "nec-pc-engine" @@ -176270,7 +176271,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -176482,6 +176483,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" @@ -177173,6 +177175,7 @@ }, "strip_components": 1, "archive_size": 9893234, + "rolling": true, "cores": [ "ppsspp" ] diff --git a/install/lakka.json b/install/lakka.json index 5724a3883..11ab477e1 100644 --- a/install/lakka.json +++ b/install/lakka.json @@ -128400,7 +128400,8 @@ } }, "strip_components": 0, - "archive_size": 4465709 + "archive_size": 4465709, + "rolling": true }, { "ref": "cemu-gameprofiles", @@ -129414,6 +129415,7 @@ }, "strip_components": 0, "archive_size": 175384, + "rolling": true, "cores": [ "dirksimple" ] @@ -129421,7 +129423,7 @@ { "ref": "fbneo-cheats", "dest": "fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [ "arcade", @@ -143125,7 +143127,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -143339,6 +143341,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" @@ -143347,7 +143350,7 @@ { "ref": "freeintv-overlays", "dest": "freeintv_overlays", - "url": "https://github.com/libretro/FreeIntv/raw/master/Assets/Overlays.zip", + "url": "https://github.com/libretro/FreeIntv/raw/ef3e0fe322bec62a7f916c0bb0834c08c348d0b4/Assets/Overlays.zip", "type": "zip", "systems": [ "mattel-intellivision" diff --git a/install/launchers/index.json b/install/launchers/index.json index 5d8796145..386d64d9d 100644 --- a/install/launchers/index.json +++ b/install/launchers/index.json @@ -27,8 +27,8 @@ { "dest": "roms/ports/retrobios/install.py", "repo_path": "install.py", - "size": 1445942, - "sha256": "86fed4f666cfb7398dbc57b285c2f493c6abb30da394a639d765162001cd0eae", + "size": 1449211, + "sha256": "3663191134988402971a3d0ae0860d6fbf158496ca03a41ff11efa4dd7a1a25b", "executable": false }, { @@ -71,8 +71,8 @@ "muos": { "archive": { "dest": "ARCHIVE/RetroBIOS.muxapp", - "size": 1499567, - "sha256": "6fa5f8676ac5b1d4f7d9f4d9d0afc37a23651d7ce6f8e3427e752c9481079a4b" + "size": 1502836, + "sha256": "53057fea5643cd65d1e486ec512b55fcef721215c4f5e223783c6d133a1ae4b6" }, "members": [ { @@ -92,8 +92,8 @@ { "name": "RetroBIOS/install.py", "repo_path": "install.py", - "size": 1445942, - "sha256": "86fed4f666cfb7398dbc57b285c2f493c6abb30da394a639d765162001cd0eae", + "size": 1449211, + "sha256": "3663191134988402971a3d0ae0860d6fbf158496ca03a41ff11efa4dd7a1a25b", "executable": false }, { @@ -166,8 +166,8 @@ { "dest": ".config/modules/retrobios/install.py", "repo_path": "install.py", - "size": 1445942, - "sha256": "86fed4f666cfb7398dbc57b285c2f493c6abb30da394a639d765162001cd0eae", + "size": 1449211, + "sha256": "3663191134988402971a3d0ae0860d6fbf158496ca03a41ff11efa4dd7a1a25b", "executable": false }, { diff --git a/install/myminui.json b/install/myminui.json index 38f3edbfd..e6b3b2ce9 100644 --- a/install/myminui.json +++ b/install/myminui.json @@ -7,7 +7,7 @@ "platform": "myminui", "display_name": "MyMinUI", "version": "2026-08-09", - "generated": "2026-11-11T12:03:42Z", + "generated": "2026-11-13T11:31:17Z", "base_destination": "", "detect": [ { @@ -6078,7 +6078,7 @@ { "ref": "fbneo-cheats", "dest": "Bios/FBN/fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [], "files": { @@ -19776,7 +19776,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -19785,7 +19785,7 @@ { "ref": "fbneo-cheats", "dest": "Bios/NG/fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [], "files": { @@ -33483,7 +33483,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -33695,6 +33695,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" @@ -33906,6 +33907,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" diff --git a/install/nextui.json b/install/nextui.json index a1ef29050..6465238b3 100644 --- a/install/nextui.json +++ b/install/nextui.json @@ -7,7 +7,7 @@ "platform": "nextui", "display_name": "NextUI", "version": "2026-10-20", - "generated": "2026-11-09T23:51:30Z", + "generated": "2026-11-13T11:31:17Z", "base_destination": "", "detect": [ { @@ -7171,6 +7171,7 @@ }, "strip_components": 0, "archive_size": 4465709, + "rolling": true, "cores": [ "bluemsx" ] @@ -7178,7 +7179,7 @@ { "ref": "fbneo-cheats", "dest": "Bios/FBN/fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [], "files": { @@ -20876,7 +20877,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -21088,6 +21089,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" diff --git a/install/recalbox.json b/install/recalbox.json index 17a98598f..0831e284c 100644 --- a/install/recalbox.json +++ b/install/recalbox.json @@ -58964,7 +58964,7 @@ { "ref": "fbneo-cheats", "dest": "fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [ "sega-mega-drive", @@ -72665,7 +72665,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -72877,6 +72877,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" diff --git a/install/retroarch.json b/install/retroarch.json index 8263cff73..cadc2a3ab 100644 --- a/install/retroarch.json +++ b/install/retroarch.json @@ -131457,7 +131457,8 @@ } }, "strip_components": 0, - "archive_size": 4465709 + "archive_size": 4465709, + "rolling": true }, { "ref": "cemu-gameprofiles", @@ -132865,6 +132866,7 @@ }, "strip_components": 0, "archive_size": 5752250, + "rolling": true, "cores": [ "dinothawr" ] @@ -132923,6 +132925,7 @@ }, "strip_components": 0, "archive_size": 175384, + "rolling": true, "cores": [ "dirksimple" ] @@ -141597,12 +141600,13 @@ "exclude": [ "Themes" ], - "archive_size": 3197914 + "archive_size": 3197914, + "rolling": true }, { "ref": "fbneo-cheats", "dest": "fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [ "arcade", @@ -155306,7 +155310,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -155520,6 +155524,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" @@ -155528,7 +155533,7 @@ { "ref": "freeintv-overlays", "dest": "freeintv_overlays", - "url": "https://github.com/libretro/FreeIntv/raw/master/Assets/Overlays.zip", + "url": "https://github.com/libretro/FreeIntv/raw/ef3e0fe322bec62a7f916c0bb0834c08c348d0b4/Assets/Overlays.zip", "type": "zip", "systems": [ "mattel-intellivision" @@ -156586,7 +156591,8 @@ } }, "strip_components": 1, - "archive_size": 9893234 + "archive_size": 9893234, + "rolling": true }, { "ref": "yaps2-resources", diff --git a/install/retrobat.json b/install/retrobat.json index 704258374..573003c84 100644 --- a/install/retrobat.json +++ b/install/retrobat.json @@ -151487,7 +151487,7 @@ { "ref": "fbneo-cheats", "dest": "fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [ "nec-pc-engine" @@ -165187,7 +165187,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -165399,6 +165399,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" @@ -165407,7 +165408,7 @@ { "ref": "freeintv-overlays", "dest": "freeintv_overlays", - "url": "https://github.com/libretro/FreeIntv/raw/master/Assets/Overlays.zip", + "url": "https://github.com/libretro/FreeIntv/raw/ef3e0fe322bec62a7f916c0bb0834c08c348d0b4/Assets/Overlays.zip", "type": "zip", "systems": [ "mattel-intellivision" diff --git a/install/retrodeck.json b/install/retrodeck.json index 7bd69f3ab..ec35f8926 100644 --- a/install/retrodeck.json +++ b/install/retrodeck.json @@ -183050,7 +183050,7 @@ { "ref": "fbneo-cheats", "dest": "bios/fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [ "arcade", @@ -196754,7 +196754,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -196968,6 +196968,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" @@ -196976,7 +196977,7 @@ { "ref": "freeintv-overlays", "dest": "bios/freeintv_overlays", - "url": "https://github.com/libretro/FreeIntv/raw/master/Assets/Overlays.zip", + "url": "https://github.com/libretro/FreeIntv/raw/ef3e0fe322bec62a7f916c0bb0834c08c348d0b4/Assets/Overlays.zip", "type": "zip", "systems": [ "mattel-intellivision" diff --git a/install/retropie.json b/install/retropie.json index 8cae94cef..33f616991 100644 --- a/install/retropie.json +++ b/install/retropie.json @@ -165938,12 +165938,13 @@ "exclude": [ "Themes" ], - "archive_size": 3197914 + "archive_size": 3197914, + "rolling": true }, { "ref": "fbneo-cheats", "dest": "fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [ "arcade", @@ -179647,7 +179648,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -179861,6 +179862,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" @@ -179869,7 +179871,7 @@ { "ref": "freeintv-overlays", "dest": "freeintv_overlays", - "url": "https://github.com/libretro/FreeIntv/raw/master/Assets/Overlays.zip", + "url": "https://github.com/libretro/FreeIntv/raw/ef3e0fe322bec62a7f916c0bb0834c08c348d0b4/Assets/Overlays.zip", "type": "zip", "systems": [ "mattel-intellivision" diff --git a/install/rocknix.json b/install/rocknix.json index b94f6ca67..10b6a766f 100644 --- a/install/rocknix.json +++ b/install/rocknix.json @@ -56023,6 +56023,7 @@ }, "strip_components": 0, "archive_size": 4465709, + "rolling": true, "cores": [ "bluemsx" ] @@ -64702,6 +64703,7 @@ "Themes" ], "archive_size": 3197914, + "rolling": true, "cores": [ "dolphin" ] @@ -64709,7 +64711,7 @@ { "ref": "fbneo-cheats", "dest": "fbneo/cheats", - "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/master.zip", + "url": "https://github.com/finalburnneo/FBNeo-cheats/archive/c72c882746580b38d8e93da27bbc41999024c08f.zip", "type": "zip", "systems": [], "files": { @@ -78407,7 +78409,7 @@ } }, "strip_components": 1, - "archive_size": 5083767, + "archive_size": 5316667, "optional": true, "cores": [ "fbneo" @@ -78619,6 +78621,7 @@ }, "strip_components": 0, "archive_size": 53006540, + "rolling": true, "optional": true, "cores": [ "fbneo" @@ -78627,7 +78630,7 @@ { "ref": "freeintv-overlays", "dest": "freeintv_overlays", - "url": "https://github.com/libretro/FreeIntv/raw/master/Assets/Overlays.zip", + "url": "https://github.com/libretro/FreeIntv/raw/ef3e0fe322bec62a7f916c0bb0834c08c348d0b4/Assets/Overlays.zip", "type": "zip", "systems": [], "files": { @@ -79685,6 +79688,7 @@ }, "strip_components": 1, "archive_size": 9893234, + "rolling": true, "cores": [ "ppsspp" ] diff --git a/installer/datadirs.py b/installer/datadirs.py index 42d74b34d..abb9ac240 100644 --- a/installer/datadirs.py +++ b/installer/datadirs.py @@ -16,6 +16,7 @@ from pathlib import Path from typing import IO, TYPE_CHECKING, BinaryIO, ContextManager from installer.download import _claim_partial, _release_claim +from installer.install_record import recorded_data_copies from installer.host_fs import ( DRIVE_FULL, NOT_WRITABLE, @@ -33,7 +34,7 @@ from installer.offline import LOCAL, _Offline, _network_allowed, _offline_only from installer.outcome import OfflineReason from installer.paths import _destination_path from installer.platforms import entry_systems -from installer.remote import MAX_DATA_ARCHIVE_SIZE, MAX_RETRIES +from installer.remote import MAX_DATA_ARCHIVE_SIZE, MAX_DOWNLOAD_SIZE, MAX_RETRIES from installer.safe_replace import KEPT, _MEMBER_ERRORS, _NotKept, _kept_slot, unreadable_words if TYPE_CHECKING: @@ -237,18 +238,30 @@ def _archive_members( yield rel, member.size, functools.partial(_tar_member, tf, member) +def _slot(entry: dict, rel: str) -> str: + """A tree member's place below the BIOS folder, as the record names it.""" + return f"{entry['dest']}/{rel}" if entry.get("dest") else rel + + def data_directory_state(entry: dict, bios_path: Path, remember: bool = False) -> tuple[Path, dict[str, dict], int]: """(tree root, files missing or wrong, files already right). remember - keeps what was read for the check after the line menu (_HEAD_READS).""" + keeps what was read for the check after the line menu (_HEAD_READS). + + A rolling tree's file is right as the list hashes it or as an earlier + run wrote it from the source (the install record): the source has moved + on from the pack's copy, and that file is the newer one.""" root = _destination_path(bios_path, entry["dest"]) if entry.get("dest") else bios_path.resolve() needed: dict[str, dict] = {} present = 0 + written = recorded_data_copies(bios_path) if entry.get("rolling") else {} for rel, meta in entry["files"].items(): target = _destination_path(root, rel) + accepted = {(meta["sha1"], meta["size"])} | written.get(_slot(entry, rel).casefold(), set()) try: - held = (target.is_file() and target.stat().st_size == meta["size"] - and _read_digests(target, ("sha1",), remember)["sha1"] == meta["sha1"]) + size = target.stat().st_size if target.is_file() else -1 + held = (any(size == known for _sha1, known in accepted) + and (_read_digests(target, ("sha1",), remember)["sha1"], size) in accepted) except OSError: held = False if held: @@ -294,8 +307,17 @@ def install_data_directory(entry: dict, bios_path: Path, state is the tree's data_directory_state when the run already read it: each read hashes every file in place. - Returns counts: present, installed, changed (the source no longer holds - the recorded bytes), absent (not in the archive), error, the reason + A rolling tree (a source that names no revision, the buildbot's nightly + assets) is written as its source serves it now, as RetroArch's own + downloader writes it: a member whose bytes differ from the list is + written all the same, read to the size its archive declares and, in a + ZIP, checked against its CRC-32. A tree listed at a commit keeps only + the listed bytes. + + Returns counts: present, installed, updated (of those installed, the + ones a rolling source holds newer than the list), changed (the source + no longer holds the recorded bytes), absent (not in the archive), error, + the reason the archive could not be read, not_kept, the (path, reason) of each file in place that differs and could not be moved aside, left as it is, and written, each file written (dest below the BIOS folder, sha1, size). @@ -304,9 +326,11 @@ def install_data_directory(entry: dict, bios_path: Path, needed = dict(needed) written: list[dict] = [] not_kept: list[tuple[str, str]] = [] - tallies = {"installed": 0, "changed": 0} + tallies = {"installed": 0, "updated": 0, "changed": 0} + # From a pack, the pack's copy is the tree: nothing newer to follow. + rolling = bool(entry.get("rolling")) and LOCAL.pack is None counts: dict[str, object] = { - "present": present, "installed": 0, "changed": 0, "absent": 0, "error": "", + "present": present, "installed": 0, "updated": 0, "changed": 0, "absent": 0, "error": "", "not_kept": not_kept, "written": written} if not needed: return counts @@ -339,19 +363,24 @@ def install_data_directory(entry: dict, bios_path: Path, # Read no more than the list records: the archive's own size # field is checked first, and the stream is cut at the # expected size whatever the member claims, so a member that - # inflates without end costs one byte past it. - if declared != meta["size"]: + # inflates without end costs one byte past it. A rolling + # source's member is cut at the size its archive declares. + if declared != meta["size"] and not (rolling and 0 <= declared <= MAX_DOWNLOAD_SIZE): tallies["changed"] += 1 continue target = _destination_path(root, rel) target.parent.mkdir(parents=True, exist_ok=True) - slot = f"{entry['dest']}/{rel}" if entry.get("dest") else rel - outcome = _install_data_member( - opener, meta, target, bios_path, slot, rel, not_kept) + slot = _slot(entry, rel) + outcome, landed = _install_data_member( + opener, meta, target, bios_path, slot, rel, not_kept, + declared if rolling else None) if outcome: tallies[outcome] += 1 - if outcome == "installed": - written.append({"dest": slot, "sha1": meta["sha1"], "size": meta["size"]}) + if outcome == "updated": + # Installed too: updated counts the newer ones among them. + tallies["installed"] += 1 + if landed is not None: + written.append({"dest": slot, **landed}) except _Offline as exc: # Kept apart, so the advice is the offline one, not the network's. counts["error"] = OfflineReason(str(exc)) @@ -375,6 +404,7 @@ def install_data_directory(entry: dict, bios_path: Path, if lock is not None: _release_claim(lock, lock_path) counts["installed"] = tallies["installed"] + counts["updated"] = tallies["updated"] counts["changed"] = tallies["changed"] counts["absent"] = len(needed) return counts @@ -383,11 +413,17 @@ def install_data_directory(entry: dict, bios_path: Path, def _install_data_member( opener: Callable[[], ContextManager[IO[bytes]]], meta: dict, target: Path, bios_path: Path, slot: str, rel: str, not_kept: list[tuple[str, str]], -) -> str: + follow: int | None = None, +) -> tuple[str, dict | None]: """Write one member of a data tree's archive at target once its bytes - are the recorded ones: "installed", "changed" when they are not, or "" - when the file in place could not be moved aside (named in not_kept). + are the recorded ones: ("installed", what landed), ("changed", None) + when they are not, or ("", None) when the file in place could not be + moved aside (named in not_kept). follow is the size a rolling source's + archive declares for the member: its bytes land whatever they hash to, + ("updated", what landed) when they are not the listed ones, and a + stream that ends short of that size or runs past it is "changed". A read or write error is raised, and leaves no .part behind.""" + expected = meta["size"] if follow is None else follow scratch: Path | None = None try: digest = hashlib.sha1() @@ -396,23 +432,27 @@ def _install_data_member( dir=target.parent, prefix=f".{target.name}.", suffix=".part", delete=False, ) as out: scratch = Path(out.name) - while size <= meta["size"]: - chunk = src.read(min(1024 * 1024, meta["size"] + 1 - size)) + # Read to the end, one byte past at most: a ZIP member checks + # its CRC-32 when its stream ends, and raises when it differs. + while size <= expected: + chunk = src.read(min(1024 * 1024, expected + 1 - size)) if not chunk: break digest.update(chunk) size += len(chunk) out.write(chunk) - if digest.hexdigest() != meta["sha1"] or size != meta["size"]: - return "changed" + sha1 = digest.hexdigest() + listed = sha1 == meta["sha1"] and size == meta["size"] + if size != expected or not (listed or follow is not None): + return "changed", None try: - KEPT.keep(*_kept_slot(bios_path, slot), target, {"sha1": meta["sha1"]}) + KEPT.keep(*_kept_slot(bios_path, slot), target, {"sha1": sha1}) except _NotKept as exc: not_kept.append((rel, str(exc))) - return "" + return "", None os.replace(scratch, target) scratch = None - return "installed" + return ("installed" if listed else "updated"), {"sha1": sha1, "size": size} finally: if scratch is not None: scratch.unlink(missing_ok=True) diff --git a/installer/install_record.py b/installer/install_record.py index 219cd7a85..4860e443b 100644 --- a/installer/install_record.py +++ b/installer/install_record.py @@ -286,6 +286,17 @@ def record_file(entry: dict, origin: str, root: str = "") -> dict: "from": origin} +def recorded_data_copies(folder: Path) -> dict[str, set[tuple[str, int]]]: + """The data tree files earlier runs wrote in folder, as its record names + them: (sha1, size) of each, by destination casefolded.""" + copies: dict[str, set[tuple[str, int]]] = {} + for setup in ((load_record(folder).data or {}).get("setups") or {}).values(): + for item in setup.get("files") or []: + if str(item.get("root") or "") == "data": + copies.setdefault(item["dest"].casefold(), set()).add((item["sha1"], item["size"])) + return copies + + def write_record( folder: Path, plat: str, manifest: dict, choice: list[str], files: list[dict], ) -> tuple[Path | None, dict, str]: diff --git a/installer/manifest.py b/installer/manifest.py index 8e0eb769e..cd5887575 100644 --- a/installer/manifest.py +++ b/installer/manifest.py @@ -513,8 +513,9 @@ def _check_data_directory(entry: object, where: str) -> None: values = entry.get(field, []) if not isinstance(values, list) or not all(isinstance(v, str) for v in values): raise ValueError(f"{where}.{field} is invalid") - if entry.get("optional", True) is not True: - raise ValueError(f"{where}.optional is invalid") + for flag in ("optional", "rolling"): + if entry.get(flag, True) is not True: + raise ValueError(f"{where}.{flag} is invalid") cores = entry.get("cores", ["-"]) if not isinstance(cores, list) or not cores or not all(isinstance(c, str) and c for c in cores): raise ValueError(f"{where}.cores is invalid") diff --git a/installer/pack.py b/installer/pack.py index 086403303..5b5dd9cf0 100644 --- a/installer/pack.py +++ b/installer/pack.py @@ -791,7 +791,9 @@ def _fill_pack(args: argparse.Namespace, pack: _PackFill, staging: Path, if not owned: continue detail(f" {entry.get('ref', 'data')}: {_plural(len(names), 'data file')}...") - counts = install_data_directory(entry, root) + # The pack is rebuilt byte for byte: its tree is the listed one, + # never what a rolling source serves since. + counts = install_data_directory({**entry, "rolling": False}, root) problem = (str(counts["error"]) if counts["error"] else f"{counts['changed']} changed in its source" if counts["changed"] else f"{counts['absent']} not in its source" if counts["absent"] diff --git a/installer/run.py b/installer/run.py index 40da74f71..b814e7ed5 100644 --- a/installer/run.py +++ b/installer/run.py @@ -555,6 +555,9 @@ def _pass_install_tree(run: _InstallRun, p: _PlatformPass, entry: dict, # said so of 218 files no source was asked for. line = f" {entry['ref']}: {counts['installed']} installed, " \ f"{counts['present']} already in place" + if counts["updated"]: + # A rolling source moved on since the list: its bytes landed. + line += f", {counts['updated']} newer than the pack's (as {entry['url']} serves them)" if counts["changed"] or counts["absent"]: # From a pack, the pack is the source that lacks them. line += (f", {counts['changed'] + counts['absent']} not in " diff --git a/platforms/_data_dirs.yml b/platforms/_data_dirs.yml index 825a5fdc7..5b47cd86a 100644 --- a/platforms/_data_dirs.yml +++ b/platforms/_data_dirs.yml @@ -18,6 +18,15 @@ # tests/test_core_data_trees.py fails on a reader with neither. # # Each entry cites the original emulator source code that requires the directory. +# +# A source_url with {version} on GitHub or GitLab names a revision: the +# refresh reads the commit the branch points to, fetches the tree at that +# commit and records it, and the install lists carry that commit's address, +# whose bytes never change. Write such an address so it takes a commit +# (archive/{version}.tar.gz, never archive/refs/heads/{version}), and a +# tarball's source_path with {version}. A source with no revision (the +# buildbot's nightly assets, a release asset) is followed: the installer +# writes what it serves, as RetroArch's own downloader does. data_directories: @@ -251,9 +260,9 @@ data_directories: # ref: syobonaction (system/syobonaction/) # Freeware game data from OpenSyobonAction (BGM, res, SE directories) syobonaction: - source_url: "https://github.com/akemin-dayo/OpenSyobonAction/archive/refs/heads/{version}.tar.gz" + source_url: "https://github.com/akemin-dayo/OpenSyobonAction/archive/{version}.tar.gz" source_type: tarball - source_path: "OpenSyobonAction-master" + source_path: "OpenSyobonAction-{version}" version: master local_cache: data/syobonaction exclude: [DxLib.cpp, DxLib.h, icon.ico, joyconfig.h, loadg.cpp, main.cpp, main.h, Makefile, README_ja.md, README.md] @@ -283,9 +292,9 @@ data_directories: # Not on buildbot, sourced from libretro repo # 532 files (tiles, fonts, databases, lua scripts, level descriptions) stonesoup: - source_url: "https://github.com/libretro/crawl-ref/archive/refs/heads/{version}.tar.gz" + source_url: "https://github.com/libretro/crawl-ref/archive/{version}.tar.gz" source_type: tarball - source_path: "crawl-ref-master/crawl-ref/source/dat" + source_path: "crawl-ref-{version}/crawl-ref/source/dat" version: master local_cache: data/stonesoup description: "DCSS game data (tiles, fonts, databases, lua, level descriptions)" @@ -293,7 +302,7 @@ data_directories: # ref: FBNeo src/burner/libretro/libretro.cpp (system/fbneo/cheats/) # No platform installs it. Never opened: romm (one file per core). fbneo-cheats: - source_url: "https://github.com/finalburnneo/FBNeo-cheats/archive/refs/heads/{version}.zip" + source_url: "https://github.com/finalburnneo/FBNeo-cheats/archive/{version}.zip" source_type: zip version: master local_cache: data/fbneo-cheats diff --git a/schemas/install-manifest.schema.json b/schemas/install-manifest.schema.json index 7098974ad..cd59cc04b 100644 --- a/schemas/install-manifest.schema.json +++ b/schemas/install-manifest.schema.json @@ -479,7 +479,7 @@ "uniqueItems": true }, "data_directories": { - "description": "Data trees the pack carries, rebuilt by the installer from their source archive. Each file is kept only when its sha1 matches.", + "description": "Data trees the pack carries, rebuilt by the installer from their source archive. Each file is kept only when its sha1 matches, except in a rolling tree, which is written as its source serves it.", "type": "array", "items": { "type": "object", @@ -547,6 +547,11 @@ "const": true, "description": "Every core reading the tree runs without it (required: false in its profile): --required-only leaves it out." }, + "rolling": { + "type": "boolean", + "const": true, + "description": "The source names no revision (the buildbot's nightly assets, a release asset): the installer writes each listed file as the source serves it now, as RetroArch's downloader does, and the hashes describe the pack's copy. Absent for a source listed at a commit, whose files must hash as listed." + }, "cores": { "type": "array", "items": { diff --git a/scripts/installer_build/installerdoc.py b/scripts/installer_build/installerdoc.py index ff5109ed4..22417cf68 100644 --- a/scripts/installer_build/installerdoc.py +++ b/scripts/installer_build/installerdoc.py @@ -351,7 +351,7 @@ def _child(spec: dict) -> int: def tree_landed(entry: dict, _bios: Path, state: object = None, _progress: object = None) -> dict: - return {"present": 0, "installed": len(entry["files"]), "changed": 0, + return {"present": 0, "installed": len(entry["files"]), "updated": 0, "changed": 0, "absent": 0, "error": "", "not_kept": []} def tree_held(entry: dict, bios: Path, remember: bool = False) -> tuple: diff --git a/scripts/packs/datadirs.py b/scripts/packs/datadirs.py index 1d2a33c90..7ad8815c4 100644 --- a/scripts/packs/datadirs.py +++ b/scripts/packs/datadirs.py @@ -220,6 +220,16 @@ def _parse_repo_from_url(source_url: str) -> tuple[str, str, str]: raise ValueError(f"Unsupported host in URL: {source_url}") +def revisioned(entry: dict) -> bool: + """Whether the source names a forge revision: {version} in a GitHub or + GitLab address. Such a tree is fetched at the commit its branch points + to, recorded, and listed at that commit, whose bytes never change. Any + other source (the buildbot's nightly assets, a release asset) names no + revision: what it serves today is all it holds.""" + url = str(entry.get("source_url", "")) + return "{version}" in url and ("github.com/" in url or "gitlab.com/" in url) + + def get_remote_sha(source_url: str, version: str) -> str | None: """Fetch the current commit SHA for a branch/tag from GitHub or GitLab.""" try: @@ -441,7 +451,10 @@ def _record_archive_size(key: str, entry: dict, versions_path: str) -> None: record = versions.get(key) if record is None or "archive_size" in record: return - version = entry.get("version", "master") + # The archive of the commit the tree was fetched at, which the + # install lists name, never the one its branch points to now. + version = (record.get("sha") if revisioned(entry) and record.get("sha") + else entry.get("version", "master")) size = _measure_archive(entry["source_url"].format(version=version)) if size is None: return @@ -507,6 +520,14 @@ def refresh_entry( return _refresh_entry(key, entry, force, dry_run, versions_path) +def _remote_tag(entry: dict, version: str) -> str | None: + """The commit a revisioned source's branch points to, else the ETag of + what the address serves.""" + if revisioned(entry): + return get_remote_sha(entry["source_url"], version) + return _get_remote_etag(entry["source_url"].format(version=version)) + + def _decide( key: str, entry: dict, force: bool, versions_path: str ) -> tuple[bool | None, str | None, str | None]: @@ -517,10 +538,7 @@ def _decide( cached_tag = cached.get("sha") or cached.get("etag") if force or not Path(entry["local_cache"]).exists(): return True, None, cached_tag - if entry.get("source_type", "tarball") == "zip": - remote_tag = _get_remote_etag(entry["source_url"].format(version=version)) - else: - remote_tag = get_remote_sha(entry["source_url"], version) + remote_tag = _remote_tag(entry, version) if remote_tag is None: log.warning("[%s] could not check remote, skipping", key) return None, None, cached_tag @@ -557,10 +575,12 @@ def _refresh_entry( # Read before the download. A release published in between then # leaves an older tag on newer content, which the next run refreshes. # Read after, it left a newer tag on older content, trusted for good. - if source_type == "zip": - remote_tag = _get_remote_etag(source_url) - else: - remote_tag = get_remote_sha(entry["source_url"], version) + remote_tag = _remote_tag(entry, version) + # A branch is fetched at the commit read above, never at its name: read + # by name, a push in between left the recorded commit on other bytes, + # and the list the installer checks named a revision it never had. + at = remote_tag if revisioned(entry) and remote_tag else version + source_url = entry["source_url"].format(version=at) archive_sizes: list[int] = [] @@ -571,7 +591,7 @@ def _refresh_entry( source_url, local_cache, exclude, entry.get("strip_components", 0), measured=archive_sizes.append, ) - source_path = entry["source_path"].format(version=version) + source_path = entry["source_path"].format(version=at) return _download_and_extract( source_url, source_path, local_cache, exclude, measured=archive_sizes.append ) diff --git a/scripts/packs/datatrees.py b/scripts/packs/datatrees.py index 3771ec054..7076b4ffd 100644 --- a/scripts/packs/datatrees.py +++ b/scripts/packs/datatrees.py @@ -4,6 +4,7 @@ from __future__ import annotations import json import os +import re import zipfile from collections.abc import Iterable, Iterator from pathlib import Path @@ -15,7 +16,7 @@ from model.declarations import declared_root from model.profiles import entry_system_ids, installed_data_refs from model.systems import norm_system_id from packs.archive import PackRecord, add_pack_member -from packs.datadirs import cache_lock +from packs.datadirs import cache_lock, revisioned from packs.extras import prefixed_destination from packs.paths import MEDIA_MARKER, has_path_conflict, register_path, lands_on_android from resolve.cores import resolve_platform_cores as _platform_cores @@ -26,6 +27,8 @@ from resolve.validation import deliverable, read_from_system_dir if TYPE_CHECKING: from typing_extensions import Unpack +_COMMIT = re.compile(r"[0-9a-f]{40}") + def pack_markers( platform_name: str, target_name: str | None, platforms_dir: str @@ -309,7 +312,15 @@ def _tree_group( ``versions`` caches each .versions.json read, by path. """ + recorded = _recorded_version(ref, entry, versions) version = str(entry.get("version", "master")) + revision = str(recorded.get("sha") or "") + rolling = not revisioned(entry) + if not rolling and recorded.get("version") == version and _COMMIT.fullmatch(revision): + # The commit the cache was fetched at, not the branch's name. + version = revision + elif not _COMMIT.fullmatch(version): + rolling = True dest = prefix if base_dest and (dest == base_dest or dest.startswith(base_dest + "/")): dest = dest[len(base_dest):].lstrip("/") @@ -327,20 +338,30 @@ def _tree_group( group["source_path"] = str(entry.get("source_path", "")).format(version=version) if entry.get("exclude"): group["exclude"] = [str(e) for e in entry["exclude"]] - cache = entry.get("local_cache") - if cache: - recorded = Path(cache).parent / ".versions.json" - if str(recorded) not in versions: - try: - versions[str(recorded)] = json.loads(recorded.read_text()) - except FileNotFoundError: - versions[str(recorded)] = {} - size = versions[str(recorded)].get(ref, {}).get("archive_size") - if isinstance(size, int) and size > 0: - group["archive_size"] = size + size = recorded.get("archive_size") + if isinstance(size, int) and size > 0: + group["archive_size"] = size + if rolling: + group["rolling"] = True return group +def _recorded_version(ref: str, entry: dict, versions: dict[str, dict[str, dict]]) -> dict: + """What refresh_data_dirs recorded of the tree's last fetch, read once + per .versions.json.""" + cache = entry.get("local_cache") + if not cache: + return {} + recorded = Path(cache).parent / ".versions.json" + if str(recorded) not in versions: + try: + versions[str(recorded)] = json.loads(recorded.read_text()) + except FileNotFoundError: + versions[str(recorded)] = {} + found = versions[str(recorded)].get(ref) + return found if isinstance(found, dict) else {} + + def manifest_data_directories( members: list[tuple[str, str]], refs: dict[str, tuple[str, tuple[str, ...], str, bool]], @@ -354,8 +375,12 @@ def manifest_data_directories( The source archive and the rule that maps its members onto the tree (strip_components for a ZIP, source_path for a tarball, exclude) come from _data_dirs.yml, the same refresh_data_dirs applies. Every file - carries the sha1 and size the cache holds, so a member the source - changed since is refused rather than installed. archive_size is the + carries the sha1 and size the cache holds. A source that names a + revision is listed at the commit the cache was fetched at, so its + members never change; one that names none (the buildbot's nightly + assets) is ``rolling``: the installer writes what it serves, as + RetroArch's downloader does, and the hashes describe the pack's copy. + archive_size is the size of the archive refresh_data_dirs last downloaded, what fetching the tree costs: a tarball whose tree is 10 KB is a download of 21 MB. ``systems`` are the platform's ids (``platform_systems``) the tree's diff --git a/tests/test_install.py b/tests/test_install.py index bf00d4c8a..7e275d96f 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -509,7 +509,7 @@ class TheDataTreesCountInTheFreeSpace(unittest.TestCase): unittest.mock.patch.object( install, "install_data_directory", lambda entry, *a, fetched=fetched, **k: fetched.append(entry["ref"]) or { - "present": 0, "installed": 1, "changed": 0, "absent": 0, + "present": 0, "installed": 1, "updated": 0, "changed": 0, "absent": 0, "error": "", "not_kept": []}), \ contextlib.redirect_stdout(out), contextlib.redirect_stderr(out): try: @@ -4378,6 +4378,91 @@ class DataDirectoriesAreInstalled(unittest.TestCase): self.assertEqual(again["present"], 1) self.assertEqual(sorted(p.name for p in (bios / "dolphin-emu").iterdir()), ["Sys"]) + def _served(self, archive: Path): + def fetch(url, directory, progress=None, keep=None): + copy = Path(directory) / "a.zip" + shutil.copy(archive, copy) + return copy + return fetch + + def test_a_rolling_tree_lands_what_its_source_serves(self): + """The buildbot rebuilt PPSSPP.zip and 49 of its 169 files were + refused on every install: a nightly source holds no other bytes. + RetroArch's own downloader writes what the buildbot serves.""" + work = Path(_tempdir(self)) + bios = work / "system" + bios.mkdir() + entry = {**self._entry(), "rolling": True} + with unittest.mock.patch.object(install, "_fetch_archive", self._served(self._zip(work))): + counts = install.install_data_directory(entry, bios) + self.assertEqual((counts["installed"], counts["updated"], counts["changed"], + counts["absent"]), (2, 1, 0, 1)) + dsp = bios / "dolphin-emu" / "Sys" / "GC" / "dsp.bin" + self.assertEqual(dsp.read_bytes(), b"new bytes upstream") + self.assertIn({"dest": "dolphin-emu/Sys/GC/dsp.bin", + "sha1": hashlib.sha1(b"new bytes upstream").hexdigest(), + "size": len(b"new bytes upstream")}, counts["written"]) + self.assertFalse((bios / "dolphin-emu" / "Themes").exists()) + + def test_a_rolling_file_an_earlier_run_wrote_is_in_place(self): + """Its bytes are not the list's, they are what the source served and + the record names: the next run neither fetches nor rewrites it.""" + work = Path(_tempdir(self)) + bios = work / "system" + bios.mkdir() + entry = {**self._entry(), "rolling": True} + with unittest.mock.patch.object(install, "_fetch_archive", self._served(self._zip(work))): + counts = install.install_data_directory(entry, bios) + files = [install.record_file(item, "download", "data") for item in counts["written"]] + install.write_record(bios, "retroarch", {}, [], files) + _root, needed, present = install.data_directory_state(entry, bios) + self.assertEqual((sorted(needed), present), (["Sys/GC/gone.bin"], 2)) + # Changed on the drive since: neither the list's bytes nor the run's. + (bios / "dolphin-emu" / "Sys" / "GC" / "dsp.bin").write_bytes(b"new bytes upstreaM") + self.assertIn("Sys/GC/dsp.bin", install.data_directory_state(entry, bios)[1]) + # A tree listed at a commit takes only the list's bytes. + self.assertIn("Sys/GC/dsp.bin", install.data_directory_state(self._entry(), bios)[1]) + + def test_a_damaged_rolling_member_is_never_written(self): + """No hash to hold a followed member to: its ZIP CRC-32 still is.""" + import zipfile + + work = Path(_tempdir(self)) + archive = self._zip(work) + body = bytearray(archive.read_bytes()) + at = body.index(b"new bytes upstream") + body[at] ^= 0x01 + archive.write_bytes(bytes(body)) + bios = work / "system" + bios.mkdir() + with unittest.mock.patch.object(install, "_fetch_archive", self._served(archive)): + counts = install.install_data_directory({**self._entry(), "rolling": True}, bios) + self.assertTrue(counts["error"]) + self.assertFalse((bios / "dolphin-emu" / "Sys" / "GC" / "dsp.bin").exists()) + self.assertEqual([p.name for p in (bios / "dolphin-emu" / "Sys" / "GC").iterdir() + if p.name.endswith(".part")], []) + self.assertTrue(zipfile.is_zipfile(archive)) + + def test_a_pack_rebuilds_a_rolling_tree_as_listed(self): + """From a pack, the pack's copy is the tree: nothing newer exists.""" + work = Path(_tempdir(self)) + bios = work / "system" + bios.mkdir() + + def tree(_dest): + yield "Sys/GC/dsp.bin", 18, lambda: io.BytesIO(b"new bytes upstream") + + local = unittest.mock.Mock() + local.tree = tree + with unittest.mock.patch.object(install.LOCAL, "pack", local): + counts = install.install_data_directory({**self._entry(), "rolling": True}, bios) + self.assertEqual((counts["installed"], counts["updated"], counts["changed"]), (0, 0, 1)) + + def test_a_rolling_flag_is_true_or_absent(self): + with self.assertRaisesRegex(ValueError, "rolling is invalid"): + install._check_data_directory({**self._entry(), "rolling": False}, "d") + install._check_data_directory({**self._entry(), "rolling": True}, "d") + def test_a_member_that_inflates_is_cut_at_its_size(self): # A member whose header claims the recorded size and whose stream # never ends: reading stops one byte past it. diff --git a/tests/test_refresh_data_dirs.py b/tests/test_refresh_data_dirs.py index 5faf62436..688165f2d 100644 --- a/tests/test_refresh_data_dirs.py +++ b/tests/test_refresh_data_dirs.py @@ -325,5 +325,83 @@ class TheManifestCarriesTheArchiveSize(unittest.TestCase): self.assertNotIn("optional", listed["pak"]) +class ASourceThatMovesIsPinnedOrFollowed(unittest.TestCase): + """The PPSSPP list pinned the bytes of a buildbot nightly: six days after + the buildbot rebuilt it, 49 of its 169 files were refused on every + install. A source with a revision is listed at the commit it was fetched + at; one with none is marked rolling, and the installer follows it.""" + + COMMIT = "c" * 40 + + def _listed(self, registry: dict, versions: dict) -> dict[str, dict]: + from packs.datatrees import manifest_data_directories + + (REPO_ROOT / "tmp").mkdir(exist_ok=True) + with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + data = Path(tmp) / "data" + for ref, entry in registry.items(): + (data / ref).mkdir(parents=True) + (data / ref / "a.bin").write_bytes(b"abc") + entry["local_cache"] = str(data / ref) + (data / ".versions.json").write_text(json.dumps(versions)) + members = [(str(data / ref / "a.bin"), f"{ref}/a.bin") for ref in registry] + refs = {f"{ref}/a.bin": (ref, ("s",), ref, True) for ref in registry} + return {entry["ref"]: entry for entry in + manifest_data_directories(members, refs, registry, "")} + + def test_a_branch_is_listed_at_the_commit_it_was_fetched_at(self): + listed = self._listed( + {"git": {"source_type": "tarball", "version": "master", + "source_url": "https://github.com/o/r/archive/{version}.tar.gz", + "source_path": "r-{version}/dat"}, + "nightly": {"source_type": "zip", + "source_url": "https://buildbot.libretro.com/assets/system/P.zip"}, + "unrecorded": {"source_type": "zip", "version": "master", + "source_url": "https://github.com/o/u/archive/{version}.zip"}}, + {"git": {"sha": self.COMMIT, "version": "master"}, + "nightly": {"sha": '"1261709225"', "version": "master"}}) + self.assertEqual(listed["git"]["url"], f"https://github.com/o/r/archive/{self.COMMIT}.tar.gz") + self.assertEqual(listed["git"]["source_path"], f"r-{self.COMMIT}/dat") + self.assertNotIn("rolling", listed["git"]) + self.assertIs(listed["nightly"]["rolling"], True) + # No commit recorded: the branch's name is all the list can carry. + self.assertIs(listed["unrecorded"]["rolling"], True) + + def test_a_branch_is_fetched_at_the_commit_it_records(self): + (REPO_ROOT / "tmp").mkdir(exist_ok=True) + with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + versions = str(Path(tmp) / ".versions.json") + entry = {"source_type": "zip", "version": "master", "strip_components": 1, + "source_url": "https://github.com/o/r/archive/{version}.zip", + "local_cache": str(Path(tmp) / "r")} + fetched: list[str] = [] + + def extract(url, *args, **kwargs): + fetched.append(url) + return 1 + + with mock.patch.object(datadirs, "get_remote_sha", return_value=self.COMMIT), \ + mock.patch.object(datadirs, "_get_remote_etag", + side_effect=AssertionError("an ETag for a revision")), \ + mock.patch.object(datadirs, "_download_and_extract_zip", extract): + self.assertTrue(datadirs.refresh_entry("r", entry, force=True, + versions_path=versions)) + self.assertEqual(fetched, [f"https://github.com/o/r/archive/{self.COMMIT}.zip"]) + self.assertEqual(load_versions(versions)["r"], + {"sha": self.COMMIT, "version": "master"}) + + def test_every_forge_source_takes_a_commit(self): + """archive/refs/heads/ is no address: a forge source must be + written so the commit the refresh reads can replace its branch.""" + registry = datadirs.load_registry(str(REPO_ROOT / "platforms" / "_data_dirs.yml")) + for key, entry in registry.items(): + if not datadirs.revisioned(entry): + continue + with self.subTest(key): + self.assertNotIn("refs/heads/", entry["source_url"]) + if entry.get("source_type", "tarball") == "tarball": + self.assertIn("{version}", entry["source_path"]) + + if __name__ == "__main__": unittest.main() diff --git a/wiki/installer.md b/wiki/installer.md index 60fc40d69..fb5ceae7f 100644 --- a/wiki/installer.md +++ b/wiki/installer.md @@ -2031,8 +2031,13 @@ PPSSPP's assets, blueMSX's machines. These are not files of the collection, so upstream release) and the sha1 and size of every file the pack carries. The installer downloads the archive once, maps its members the way the pack was built (`strip_components` for a ZIP, `source_path` for a tarball, `exclude`), -and writes a file only when its hash matches the list. A file the source has -changed since is left out and counted, and the pack still holds it. `--check` +and writes a file only when its hash matches the list. A source that names a +revision is listed at the commit `refresh_data_dirs.py` fetched, so its files +never change. A source that names none, the buildbot's nightly assets, is +marked `rolling`: it holds only its latest build, so the installer writes each +file as the source serves it now, as RetroArch's own downloader does, checked +against its ZIP CRC-32, and says how many are newer than the pack's. The next +run takes those files as in place through the install record. `--check` counts the data files missing, `--dry-run` names each tree it would fetch, and the size announced for a tree is its archive's (`archive_size`, recorded when `refresh_data_dirs.py` last downloaded it): one missing file fetches the whole