mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-27 11:58:53 -06:00
feat: pin forge data trees, follow nightly ones
A data tree whose source names a revision is fetched at the commit its branch points to and listed at that commit, whose bytes never change. A source with no revision (the buildbot's nightly assets) is marked rolling: the installer writes each listed file as the source serves it, checked against its ZIP CRC-32, as RetroArch's own downloader does, and the install record keeps it in place on the next run. The PPSSPP list refused 49 of 169 files after each buildbot rebuild.
This commit is contained in:
1 parent
2cbffb11f9
commit
ff69210b18
31 files changed
+524
-145
No files matched your search
@@ -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:
|
||||
|
||||
+30
-10
@@ -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
|
||||
)
|
||||
|
||||
+39
-14
@@ -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
|
||||
|
||||
Reference in new issue
Block a user