mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 14:28:54 -06:00
fix: read archive members under the collection
This commit is contained in:
1 parent
27dc26bd80
commit
95cbb5af1d
28 files changed
+104
-49
No files matched your search
@@ -16,6 +16,7 @@ import stat
|
||||
import sys
|
||||
import tempfile
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
from core.artifacts import process_umask, write_text_atomic
|
||||
from core.hashing import MAX_HASHED_MEMBER, md5sum
|
||||
@@ -199,15 +200,18 @@ def _members_md5(path: str) -> list[list] | None:
|
||||
|
||||
def build_zip_contents_index(
|
||||
db: dict,
|
||||
root: Path,
|
||||
max_entry_size: int = MAX_HASHED_MEMBER,
|
||||
cache_path: str | None = MEMBER_CACHE,
|
||||
) -> dict:
|
||||
"""Build {inner_rom_md5: zip_file_sha1} for ROMs inside ZIP files.
|
||||
|
||||
A ``.variants/`` copy counts (``neogeo.zip.1a2b3c4d`` is an archive), and
|
||||
a member a primary archive holds answers with the primary, as the
|
||||
resolver prefers it. Cached in-process, and on disk per archive sha1
|
||||
when cache_path is set.
|
||||
Each database path is read under ``root``, the folder that holds the
|
||||
collection's bios tree (model.dbpaths.collection_root). A ``.variants/``
|
||||
copy counts (``neogeo.zip.1a2b3c4d`` is an archive), and a member a
|
||||
primary archive holds answers with the primary, as the resolver prefers
|
||||
it. Cached in-process, and on disk per archive sha1 when cache_path is
|
||||
set.
|
||||
"""
|
||||
global _zip_contents_cache
|
||||
|
||||
@@ -217,7 +221,10 @@ def build_zip_contents_index(
|
||||
variant_entries: list[tuple[str, str]] = []
|
||||
for sha1, entry in db.get("files", {}).items():
|
||||
path = entry["path"]
|
||||
if is_archive_path(path) and os.path.exists(path):
|
||||
if not is_archive_path(path):
|
||||
continue
|
||||
path = str(root / path)
|
||||
if os.path.exists(path):
|
||||
primary = path.lower().endswith(".zip")
|
||||
(zip_entries if primary else variant_entries).append((path, sha1))
|
||||
primaries = len(zip_entries)
|
||||
@@ -227,6 +234,7 @@ def build_zip_contents_index(
|
||||
# second call with a smaller bound got members the first one admitted,
|
||||
# and a regenerated database got the sha1 of the old one.
|
||||
fingerprint = (
|
||||
str(root),
|
||||
max_entry_size,
|
||||
frozenset((path, os.path.getmtime(path), sha1) for path, sha1 in zip_entries),
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ file from the platform's original, and a report lists every change."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from model.dbpaths import collection_root
|
||||
import contextlib
|
||||
import functools
|
||||
import json
|
||||
@@ -14,7 +15,7 @@ from pathlib import Path
|
||||
import yaml
|
||||
|
||||
from core.artifacts import write_bytes_atomic, write_if_changed
|
||||
from core.paths import EMULATORS_DIR
|
||||
from core.paths import BIOS_DIR, EMULATORS_DIR
|
||||
from core.text import count_text
|
||||
from core.ziptools import build_zip_contents_index
|
||||
from .base_exporter import BaseExporter
|
||||
@@ -141,7 +142,7 @@ def refresh_cache(
|
||||
def _collection(db_path: str) -> tuple[dict, dict]:
|
||||
"""The database and its archive index, read once for every platform."""
|
||||
db = load_database(db_path)
|
||||
return db, build_zip_contents_index(db)
|
||||
return db, build_zip_contents_index(db, collection_root(Path(BIOS_DIR)))
|
||||
|
||||
|
||||
def doubled_in(scraped: dict | None, platforms_dir: str) -> list[dict]:
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from core.paths import BIOS_DIR
|
||||
from model.dbpaths import collection_root
|
||||
from model.registry import load_data_dir_registry
|
||||
|
||||
|
||||
@@ -29,5 +32,5 @@ def comparison_inputs(
|
||||
|
||||
db = load_database(db_path)
|
||||
groups = group_identical_platforms(list_registered_platforms(platforms_dir), platforms_dir)
|
||||
return (db, build_zip_contents_index(db), load_emulator_profiles(emulators_dir),
|
||||
return (db, build_zip_contents_index(db, collection_root(Path(BIOS_DIR))), load_emulator_profiles(emulators_dir),
|
||||
load_data_dir_registry(platforms_dir), groups)
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from model.dbpaths import collection_root
|
||||
import contextlib
|
||||
import io
|
||||
|
||||
from core.paths import DB_FILE, EMULATORS_DIR, PLATFORMS_DIR
|
||||
from core.paths import BIOS_DIR, DB_FILE, EMULATORS_DIR, PLATFORMS_DIR
|
||||
from model.profiles import reads_own_files
|
||||
from orchestrate.compare import set_difference_lines
|
||||
from orchestrate.labels import STEP_LABELS, step_title
|
||||
@@ -66,7 +68,7 @@ def check_emulator_packs(
|
||||
|
||||
print(f"\n--- {step_title(STEP_LABELS['consistency'])}, emulator packs ---")
|
||||
db = load_database(db_path)
|
||||
zip_contents = build_zip_contents_index(db)
|
||||
zip_contents = build_zip_contents_index(db, collection_root(Path(BIOS_DIR)))
|
||||
profiles = load_emulator_profiles(emulators_dir, skip_aliases=False)
|
||||
|
||||
def compare(names: list[str], standalone: bool, label: str, **narrowing: object) -> bool | None:
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from model.dbpaths import collection_root
|
||||
import os
|
||||
from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, TypedDict
|
||||
@@ -816,7 +818,7 @@ def verify_platform(
|
||||
for sys in config.get("systems", {}).values()
|
||||
for fe in sys.get("files", [])
|
||||
)
|
||||
zip_contents = build_zip_contents_index(db) if has_zipped else {}
|
||||
zip_contents = build_zip_contents_index(db, collection_root(Path(BIOS_DIR))) if has_zipped else {}
|
||||
|
||||
# Loaded before the slot overrides: a caller passing no profiles (the
|
||||
# README's coverage) got no override and reported a discrepancy at a slot
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from model.dbpaths import collection_root
|
||||
import os
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass, field
|
||||
@@ -510,7 +512,7 @@ def verify_emulator(
|
||||
# The member index only answers a zipped_file entry, and decompressing
|
||||
# every archive took 23 of the 24 seconds of a run that had none.
|
||||
zip_contents = (
|
||||
build_zip_contents_index(db)
|
||||
build_zip_contents_index(db, collection_root(Path(BIOS_DIR)))
|
||||
if any(f.get("zipped_file") for _name, profile in selected
|
||||
for f in profile.get("files") or [])
|
||||
else {}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from model.dbpaths import collection_root
|
||||
import contextlib
|
||||
import functools
|
||||
import os
|
||||
@@ -481,7 +483,7 @@ def build_emulator_pack(
|
||||
all_profiles = load_emulator_profiles(emulators_dir, skip_aliases=False)
|
||||
zip_contents = options.get("zip_contents")
|
||||
if zip_contents is None:
|
||||
zip_contents = build_zip_contents_index(db)
|
||||
zip_contents = build_zip_contents_index(db, collection_root(Path(bios_dir)))
|
||||
|
||||
try:
|
||||
selected = select_emulator_profiles(profile_names, all_profiles, standalone)
|
||||
|
||||
@@ -6,6 +6,8 @@ coverage report that disagree describe different collections."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from model.dbpaths import collection_root
|
||||
from collections import Counter
|
||||
from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, TypedDict
|
||||
@@ -214,7 +216,7 @@ def verify_pack(
|
||||
by_md5 = db.get("indexes", {}).get("by_md5", {}) # MD5 -> SHA1
|
||||
# Built on the first archive no hash recognises, once per pack: the
|
||||
# index opens every archive of the collection.
|
||||
held_inside = _once(lambda: build_zip_contents_index(db))
|
||||
held_inside = _once(lambda: build_zip_contents_index(db, collection_root(Path(BIOS_DIR))))
|
||||
by_name = db.get("indexes", {}).get("by_name", {}) # name -> [SHA1]
|
||||
|
||||
# Data directory file index
|
||||
@@ -581,7 +583,7 @@ def _builder_extras(
|
||||
config, expect.opts.emulators_dir, db, emu_profiles, shipped, expect.target_cores,
|
||||
expect.region_drops or None,
|
||||
resolver=ExtraResolver(
|
||||
db, BIOS_DIR, build_zip_contents_index(db), data_registry,
|
||||
db, BIOS_DIR, build_zip_contents_index(db, collection_root(Path(BIOS_DIR))), data_registry,
|
||||
build_validation_index(platform_profiles),
|
||||
destination_owners(platform_profiles), True, profiles=emu_profiles,
|
||||
),
|
||||
@@ -707,7 +709,7 @@ def _region_drops(
|
||||
config, emu_profiles, target_cores
|
||||
)
|
||||
held: set[str] = set()
|
||||
held_zip_contents = build_zip_contents_index(db) if db is not None else {}
|
||||
held_zip_contents = build_zip_contents_index(db, collection_root(Path(BIOS_DIR))) if db is not None else {}
|
||||
region_groups, _extra_dests = platform_region_groups(
|
||||
config,
|
||||
expected_systems,
|
||||
@@ -803,7 +805,7 @@ def _count_baseline(
|
||||
for fe in declarations
|
||||
if fe.get("group")
|
||||
}
|
||||
exclusion_index = build_zip_contents_index(db) if db is not None else {}
|
||||
exclusion_index = build_zip_contents_index(db, collection_root(Path(BIOS_DIR))) if db is not None else {}
|
||||
categories = EntryCategories(expect.config, expect.emu_profiles, data_registry)
|
||||
for expected, declarations in baseline_groups.items():
|
||||
if expected in view.zip_set:
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from model.dbpaths import collection_root
|
||||
import argparse
|
||||
import contextlib
|
||||
import os
|
||||
@@ -97,7 +99,7 @@ def _run_hash_mode(args: argparse.Namespace) -> None:
|
||||
if print_hash_lookup(lookup_hashes(hashes, db, args.bios_dir)):
|
||||
sys.exit(1)
|
||||
return
|
||||
zip_contents = build_zip_contents_index(db)
|
||||
zip_contents = build_zip_contents_index(db, collection_root(Path(args.bios_dir)))
|
||||
try:
|
||||
with pack_output_lock(args.output_dir):
|
||||
outcome = generate_md5_pack(
|
||||
@@ -222,7 +224,7 @@ def run_pack_command(
|
||||
return args
|
||||
|
||||
db = load_database(args.db)
|
||||
zip_contents = build_zip_contents_index(db)
|
||||
zip_contents = build_zip_contents_index(db, collection_root(Path(args.bios_dir)))
|
||||
if args.emulator or (args.system and not args.platform and not args.all):
|
||||
_run_profile_mode(args, db, zip_contents)
|
||||
return args
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from core.paths import PLATFORMS_DIR
|
||||
from pathlib import Path
|
||||
from model.dbpaths import collection_root
|
||||
from core.paths import BIOS_DIR, PLATFORMS_DIR
|
||||
from core.ziptools import build_zip_contents_index
|
||||
from model.platforms import load_platform_config
|
||||
from model.registry import load_data_dir_registry
|
||||
@@ -31,7 +33,7 @@ def scan_platform(
|
||||
db,
|
||||
config.get("base_destination", ""),
|
||||
platform_launches(config, profiles),
|
||||
build_zip_contents_index(db) if zip_index is None else zip_index,
|
||||
build_zip_contents_index(db, collection_root(Path(BIOS_DIR))) if zip_index is None else zip_index,
|
||||
load_data_dir_registry(platforms_dir) if data_registry is None else data_registry,
|
||||
)
|
||||
|
||||
@@ -41,7 +43,7 @@ def scan_platforms(
|
||||
target_cores: dict[str, set[str] | None], data_registry: dict,
|
||||
) -> tuple[dict[str, list[Conflict]], dict[str, list[Collision]]]:
|
||||
"""The platforms with a contested destination, and those declaring one twice."""
|
||||
zip_index = build_zip_contents_index(db)
|
||||
zip_index = build_zip_contents_index(db, collection_root(Path(BIOS_DIR)))
|
||||
found: dict[str, list[Conflict]] = {}
|
||||
collided: dict[str, list[Collision]] = {}
|
||||
for name in names:
|
||||
|
||||
@@ -32,7 +32,7 @@ from sitegen.releasepacks import NO_PACK, download_links, release_state
|
||||
|
||||
def build_file_consumers(db: dict, coverages: dict, profiles: dict) -> FileConsumers:
|
||||
"""Which platforms and emulators read each collected file."""
|
||||
consumers = FileConsumers(db, build_zip_contents_index(db))
|
||||
consumers = FileConsumers(db, build_zip_contents_index(db, siteinputs.current().db.parent))
|
||||
consumers.add_platforms({name: cov["config"] for name, cov in coverages.items()})
|
||||
consumers.add_emulators(profiles)
|
||||
consumers.add_manifests(siteinputs.manifests_dir())
|
||||
|
||||
Reference in new issue
Block a user