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())
|
||||
|
||||
@@ -163,7 +163,7 @@ class BundledHashIsProof(unittest.TestCase):
|
||||
os.chdir(REPO_ROOT)
|
||||
self.addCleanup(os.chdir, previous)
|
||||
db = load_database("database.json")
|
||||
zips = build_zip_contents_index(db)
|
||||
zips = build_zip_contents_index(db, REPO_ROOT)
|
||||
registry = load_data_dir_registry("platforms")
|
||||
wrong = []
|
||||
for name, profile in sorted(load_emulator_profiles("emulators", skip_aliases=False).items()):
|
||||
|
||||
@@ -3891,11 +3891,11 @@ class TheZipIndexCacheKnowsItsInputs(unittest.TestCase):
|
||||
archive.writestr("big.bin", b"x" * 4096)
|
||||
ziptools._zip_contents_cache = None
|
||||
db = {"files": {"a" * 40: {"path": str(path)}}}
|
||||
self.assertEqual(len(ziptools.build_zip_contents_index(db)), 1)
|
||||
self.assertEqual(ziptools.build_zip_contents_index(db, max_entry_size=10), {})
|
||||
self.assertEqual(len(ziptools.build_zip_contents_index(db, Path(directory))), 1)
|
||||
self.assertEqual(ziptools.build_zip_contents_index(db, Path(directory), max_entry_size=10), {})
|
||||
other = {"files": {"b" * 40: {"path": str(path)}}}
|
||||
self.assertEqual(
|
||||
set(ziptools.build_zip_contents_index(other).values()), {"b" * 40}
|
||||
set(ziptools.build_zip_contents_index(other, Path(directory)).values()), {"b" * 40}
|
||||
)
|
||||
ziptools._zip_contents_cache = None
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class DeclaredFilesResolveWithoutDataCaches(unittest.TestCase):
|
||||
os.chdir(REPO_ROOT)
|
||||
try:
|
||||
db = load_database("database.json")
|
||||
zip_contents = build_zip_contents_index(db)
|
||||
zip_contents = build_zip_contents_index(db, REPO_ROOT)
|
||||
offenders = []
|
||||
for platform in list_registered_platforms(str(platforms_dir)):
|
||||
config = load_platform_config(platform, str(platforms_dir))
|
||||
|
||||
+3
-3
@@ -823,7 +823,7 @@ class TestE2E(unittest.TestCase):
|
||||
self.assertNotIn(".variants", path)
|
||||
|
||||
def test_09_resolve_zip_contents(self):
|
||||
zc = build_zip_contents_index(self.db)
|
||||
zc = build_zip_contents_index(self.db, Path(self.root))
|
||||
inner_md5 = self.files["good.zip"]["inner_md5s"]["inner.rom"]
|
||||
entry = {"name": "good.zip", "md5": inner_md5, "zipped_file": "inner.rom"}
|
||||
path, status = resolve_local_file(entry, self.db, zc)
|
||||
@@ -2618,7 +2618,7 @@ class TestE2E(unittest.TestCase):
|
||||
from model.profiles import load_emulator_profiles
|
||||
from packs.platformpack import generate_split_packs
|
||||
|
||||
zip_contents = build_zip_contents_index(db)
|
||||
zip_contents = build_zip_contents_index(db, Path(tmpdir))
|
||||
emu_profiles = load_emulator_profiles(emu_dir)
|
||||
|
||||
zip_paths = generate_split_packs(
|
||||
@@ -2885,7 +2885,7 @@ class TestE2E(unittest.TestCase):
|
||||
from core.ziptools import build_zip_contents_index
|
||||
from packs.md5pack import generate_md5_pack
|
||||
|
||||
zip_contents = build_zip_contents_index(db)
|
||||
zip_contents = build_zip_contents_index(db, Path(tmpdir))
|
||||
|
||||
zip_path = generate_md5_pack(
|
||||
hashes=[("md5", h["md5"])],
|
||||
|
||||
@@ -254,7 +254,7 @@ class EveryReaderIsTheEmulatorPackFile(unittest.TestCase):
|
||||
os.chdir(REPO_ROOT)
|
||||
self.addCleanup(os.chdir, previous)
|
||||
db = json.loads(db_path.read_text(encoding="utf-8"))
|
||||
zips = build_zip_contents_index(db)
|
||||
zips = build_zip_contents_index(db, REPO_ROOT)
|
||||
registry = load_data_dir_registry(str(REPO_ROOT / "platforms"))
|
||||
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
|
||||
consumers = FileConsumers(db, zips, registry)
|
||||
|
||||
@@ -438,7 +438,7 @@ class CollectionCarriesNoGameDataHomonym(unittest.TestCase):
|
||||
try:
|
||||
db = load_database(str(database))
|
||||
profiles = load_emulator_profiles("emulators", skip_aliases=False)
|
||||
zip_index = build_zip_contents_index(db)
|
||||
zip_index = build_zip_contents_index(db, REPO_ROOT)
|
||||
registry = load_data_dir_registry("platforms")
|
||||
claims = []
|
||||
for name, profile in sorted(profiles.items()):
|
||||
|
||||
@@ -60,7 +60,7 @@ class RealListParity(unittest.TestCase):
|
||||
cls.config = staticmethod(
|
||||
lambda plat: load_platform_config(plat, str(REPO_ROOT / "platforms")))
|
||||
cls.db = json.loads(db_path.read_text(encoding="utf-8"))
|
||||
cls.zip_contents = build_zip_contents_index(cls.db)
|
||||
cls.zip_contents = build_zip_contents_index(cls.db, REPO_ROOT)
|
||||
cls.profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
|
||||
cls.by_path = {entry["path"]: sha1 for sha1, entry in cls.db["files"].items()}
|
||||
cls.platforms = list_registered_platforms(str(REPO_ROOT / "platforms"))
|
||||
|
||||
@@ -16594,7 +16594,7 @@ class EmulatorChoiceMatchesTheEmulatorPack(unittest.TestCase):
|
||||
from packs import emulatorpack
|
||||
cls.packs_archive, cls.emulatorpack = packs_archive, emulatorpack
|
||||
cls.db = json.loads(db_path.read_text(encoding="utf-8"))
|
||||
cls.zip_contents = build_zip_contents_index(cls.db)
|
||||
cls.zip_contents = build_zip_contents_index(cls.db, REPO_ROOT)
|
||||
cls.by_path = {entry["path"]: sha1 for sha1, entry in cls.db["files"].items()}
|
||||
|
||||
def pack(self, emulator: str) -> dict[str, str]:
|
||||
|
||||
@@ -38,7 +38,7 @@ class ReadersNameTheOwner(unittest.TestCase):
|
||||
|
||||
def test_the_site_credits_the_copy_the_pack_ships(self):
|
||||
consumers = FileConsumers(
|
||||
self.db, build_zip_contents_index(self.db)
|
||||
self.db, build_zip_contents_index(self.db, REPO_ROOT)
|
||||
)
|
||||
consumers.add_emulators(self.profiles)
|
||||
sha1 = self.sha1_by_path.get("bios/Arcade/MAME/neogeo.zip")
|
||||
|
||||
@@ -739,7 +739,7 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase):
|
||||
cwd = Path.cwd()
|
||||
try:
|
||||
os.chdir(root)
|
||||
consumers = FileConsumers(db, build_zip_contents_index(db))
|
||||
consumers = FileConsumers(db, build_zip_contents_index(db, root))
|
||||
archive = consumers.sha1_of(entry)
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
||||
@@ -207,7 +207,7 @@ class DirectoryMembersNameTheirEmulator(unittest.TestCase):
|
||||
if cls.SHA1 not in cls.db.get("files", {}):
|
||||
raise unittest.SkipTest("the collection does not hold the alephone plugin")
|
||||
cls.profile = load_emulator_profiles(str(REPO_ROOT / "emulators"))["alephone"]
|
||||
cls.consumers = FileConsumers(cls.db, build_zip_contents_index(cls.db))
|
||||
cls.consumers = FileConsumers(cls.db, build_zip_contents_index(cls.db, REPO_ROOT))
|
||||
cls.consumers.add_emulators({"alephone": cls.profile})
|
||||
|
||||
def test_a_member_names_the_emulator_and_its_directory_entry(self):
|
||||
|
||||
+1
-1
@@ -821,7 +821,7 @@ class ManifestFollowsTheArbitration(unittest.TestCase):
|
||||
config = load_platform_config("retroarch", str(repo / "platforms"))
|
||||
profiles = load_emulator_profiles(str(repo / "emulators"))
|
||||
overrides = packs_slots.pack_overrides(
|
||||
config, profiles, db, build_zip_contents_index(db),
|
||||
config, profiles, db, build_zip_contents_index(db, repo),
|
||||
load_data_dir_registry(str(repo / "platforms")),
|
||||
)
|
||||
# RetroArch serves a core's own copy at contested slots (ATARIOSB.ROM,
|
||||
|
||||
@@ -69,7 +69,7 @@ class SplitPartsCoverTheExtras(unittest.TestCase):
|
||||
parts = generate_split_packs(
|
||||
"plat", str(root / "platforms"), db, str(root / "bios"), str(root / "dist"),
|
||||
emulators_dir=str(root / "emulators"),
|
||||
zip_contents=build_zip_contents_index(db),
|
||||
zip_contents=build_zip_contents_index(db, root),
|
||||
emu_profiles=load_emulator_profiles(str(root / "emulators")),
|
||||
)
|
||||
members = {n for p in parts for n in zipfile.ZipFile(p).namelist()}
|
||||
@@ -120,7 +120,7 @@ class SplitPartsHoldWhatTheFullPackHolds(unittest.TestCase):
|
||||
(root / "emulators" / f"{name}.yml").write_text(yaml.dump(profile))
|
||||
args = dict(
|
||||
emulators_dir=str(root / "emulators"),
|
||||
zip_contents=build_zip_contents_index(db),
|
||||
zip_contents=build_zip_contents_index(db, root),
|
||||
emu_profiles=load_emulator_profiles(str(root / "emulators")),
|
||||
offline=True,
|
||||
)
|
||||
|
||||
@@ -79,7 +79,7 @@ class SplitPartNames(unittest.TestCase):
|
||||
return generate_split_packs(
|
||||
"longplat", str(self.platforms), self.db, self.tmp.name, str(self.out),
|
||||
group_by=group_by, emulators_dir=str(self.emulators),
|
||||
zip_contents=build_zip_contents_index(self.db), emu_profiles={},
|
||||
zip_contents=build_zip_contents_index(self.db, Path(self.tmp.name)), emu_profiles={},
|
||||
)
|
||||
|
||||
def test_a_large_group_is_written(self):
|
||||
|
||||
@@ -65,7 +65,7 @@ class VariantArchives(unittest.TestCase):
|
||||
"p": {"path": str(self.primary)},
|
||||
"v": {"path": str(self.variant)},
|
||||
}}
|
||||
index = build_zip_contents_index(db, cache_path=None)
|
||||
index = build_zip_contents_index(db, self.root, cache_path=None)
|
||||
self.assertEqual(index[hashlib.md5(b"a" * 16).hexdigest()], "p")
|
||||
self.assertEqual(index[hashlib.md5(b"v" * 16).hexdigest()], "v")
|
||||
|
||||
|
||||
@@ -377,7 +377,7 @@ class RepositoryWideEvidence(unittest.TestCase):
|
||||
self.skipTest("no database.json")
|
||||
db = load_database(str(db_path))
|
||||
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
|
||||
zip_contents = build_zip_contents_index(db)
|
||||
zip_contents = build_zip_contents_index(db, REPO_ROOT)
|
||||
registry = load_data_dir_registry(str(REPO_ROOT / "platforms"))
|
||||
|
||||
offenders: list[str] = []
|
||||
|
||||
@@ -50,7 +50,7 @@ class ZippedMemberIsChecked(unittest.TestCase):
|
||||
}))
|
||||
pack = generate_pack(
|
||||
"plat", str(root / "platforms"), db, str(root / "bios"), str(root / "dist"),
|
||||
emulators_dir=str(root / "emulators"), zip_contents=build_zip_contents_index(db),
|
||||
emulators_dir=str(root / "emulators"), zip_contents=build_zip_contents_index(db, root),
|
||||
emu_profiles={}, offline=True,
|
||||
)
|
||||
names = zipfile.ZipFile(pack).namelist() if pack else []
|
||||
@@ -82,7 +82,7 @@ class VariantArchivesAreIndexed(unittest.TestCase):
|
||||
files[hashlib.sha1(data).hexdigest()] = {"path": str(path), "name": path.name}
|
||||
sha1_of = {entry["path"]: sha1 for sha1, entry in files.items()}
|
||||
ziptools._zip_contents_cache = None
|
||||
index = build_zip_contents_index({"files": files}, cache_path=None)
|
||||
index = build_zip_contents_index({"files": files}, root, cache_path=None)
|
||||
self.assertEqual(index[hashlib.md5(b"own").hexdigest()], sha1_of[str(variant)])
|
||||
self.assertEqual(index[hashlib.md5(b"shared").hexdigest()], sha1_of[str(primary)])
|
||||
|
||||
@@ -159,13 +159,13 @@ class TheMemberIndexIsCachedByContent(unittest.TestCase):
|
||||
sha1 = hashlib.sha1(archive.read_bytes()).hexdigest()
|
||||
db = {"files": {sha1: {"path": str(archive), "name": "set.zip"}}}
|
||||
cache = str(Path(tmp) / "members.json")
|
||||
first = ziptools.build_zip_contents_index(db, cache_path=cache)
|
||||
first = ziptools.build_zip_contents_index(db, Path(tmp), cache_path=cache)
|
||||
ziptools._zip_contents_cache = None
|
||||
with mock.patch.object(ziptools, "_members_md5",
|
||||
side_effect=AssertionError("archive reopened")):
|
||||
second = ziptools.build_zip_contents_index(db, cache_path=cache)
|
||||
second = ziptools.build_zip_contents_index(db, Path(tmp), cache_path=cache)
|
||||
ziptools._zip_contents_cache = None
|
||||
bounded = ziptools.build_zip_contents_index(db, max_entry_size=32,
|
||||
bounded = ziptools.build_zip_contents_index(db, Path(tmp), max_entry_size=32,
|
||||
cache_path=cache)
|
||||
ziptools._zip_contents_cache = None
|
||||
self.assertEqual(first, second)
|
||||
@@ -173,5 +173,34 @@ class TheMemberIndexIsCachedByContent(unittest.TestCase):
|
||||
hashlib.md5(b"b" * 64).hexdigest()})
|
||||
self.assertEqual(set(bounded), {hashlib.md5(b"a" * 16).hexdigest()})
|
||||
|
||||
|
||||
class TheMemberIndexReadsUnderTheCollection(unittest.TestCase):
|
||||
"""The index tested each database path against the working directory: a
|
||||
site built from another collection's database read this checkout's
|
||||
archives, and a run started elsewhere found none."""
|
||||
|
||||
def test_paths_are_read_under_the_root_whatever_the_working_directory(self):
|
||||
import os
|
||||
|
||||
from core import ziptools
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp, tempfile.TemporaryDirectory() as elsewhere:
|
||||
root = Path(tmp)
|
||||
archive = root / "bios" / "set.zip"
|
||||
archive.parent.mkdir()
|
||||
with zipfile.ZipFile(archive, "w") as zf:
|
||||
zf.writestr("own.rom", b"own")
|
||||
db = {"files": {"s" * 40: {"path": "bios/set.zip", "name": "set.zip"}}}
|
||||
previous = os.getcwd()
|
||||
os.chdir(elsewhere)
|
||||
self.addCleanup(os.chdir, previous)
|
||||
ziptools._zip_contents_cache = None
|
||||
self.addCleanup(setattr, ziptools, "_zip_contents_cache", None)
|
||||
found = build_zip_contents_index(db, root, cache_path=None)
|
||||
self.assertEqual(found, {hashlib.md5(b"own").hexdigest(): "s" * 40})
|
||||
# Another root is another answer, never the cached one.
|
||||
self.assertEqual(build_zip_contents_index(db, Path(elsewhere), cache_path=None), {})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user