mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-27 11:58:53 -06:00
fix: keep the digest cache beside the scanned tree
The cache path and .gitignore were read from the working directory: a scan of a copy replaced the repository's cache with the copy's entries, keyed bios/... like the real ones, and the next run rehashed everything. Both now come from the tree holding bios/, and kept release assets are restored under it.
This commit is contained in:
1 parent
936e9ceed9
commit
940893d7d4
6 files changed
+70
-24
No files matched your search
@@ -4,11 +4,19 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from core.artifacts import write_text_atomic
|
||||
|
||||
CACHE_DIR = ".cache"
|
||||
CACHE_FILE = os.path.join(CACHE_DIR, "db_cache.json")
|
||||
|
||||
def cache_path(bios_dir: Path) -> str:
|
||||
"""The cache of the tree holding bios_dir, beside it as its keys are relative to it.
|
||||
|
||||
A path fixed on the working directory let a scan of a copy (tmp/wt/bios)
|
||||
replace the repository's cache with the copy's entries, keyed bios/...
|
||||
like the real ones, and the next real run rehashed every file.
|
||||
"""
|
||||
return str(bios_dir.parent / ".cache" / "db_cache.json")
|
||||
|
||||
|
||||
def load_cache(cache_path: str) -> dict:
|
||||
|
||||
@@ -59,8 +59,10 @@ def surviving_entries(existing_db: dict, files: dict, registered: set[str]) -> d
|
||||
}
|
||||
|
||||
|
||||
def restore_release_assets(entries: dict, registered: set[str], *, offline: bool) -> None:
|
||||
"""Write each kept entry's asset back to its registered path, fetched only when online."""
|
||||
def restore_release_assets(
|
||||
entries: dict, registered: set[str], tree: Path, *, offline: bool
|
||||
) -> None:
|
||||
"""Write each kept entry's asset back to its registered path under tree, fetched only when online."""
|
||||
from model.largefiles import fetch_large_file, restore_verified
|
||||
|
||||
for sha1, entry in entries.items():
|
||||
@@ -72,5 +74,6 @@ def restore_release_assets(entries: dict, registered: set[str], *, offline: bool
|
||||
offline=offline,
|
||||
registered=registered,
|
||||
)
|
||||
if cached and not os.path.exists(path):
|
||||
restore_verified(cached, path, sha1)
|
||||
destination = str(tree / path)
|
||||
if cached and not os.path.exists(destination):
|
||||
restore_verified(cached, destination, sha1)
|
||||
+14
-12
@@ -8,7 +8,7 @@ from pathlib import Path
|
||||
|
||||
from collection.aliases import add_declared_aliases
|
||||
from collection.declared import UnreadableSource, read_declarations
|
||||
from collection.hashcache import CACHE_FILE, load_cache, save_cache
|
||||
from collection.hashcache import cache_path, load_cache, save_cache
|
||||
from collection.indexes import database_indexes
|
||||
from collection.record import database_record, record_retired, write_database
|
||||
from collection.releaseassets import (
|
||||
@@ -22,21 +22,20 @@ from collection.scan import scan_bios_dir
|
||||
from model import retired
|
||||
from model.dumpcatalog import annotate_provenance, load_provenance_snapshots
|
||||
|
||||
# Database entries name paths relative to the working directory, and so does
|
||||
# the registry of release assets beside them.
|
||||
GITIGNORE = Path(".gitignore")
|
||||
def preserve_release_assets(files: dict, db_path: str, tree: Path, *, offline: bool) -> int:
|
||||
"""Keep the entries of release assets the scan missed, their files restored, and count them.
|
||||
|
||||
|
||||
def preserve_release_assets(files: dict, db_path: str, *, offline: bool) -> int:
|
||||
"""Keep the entries of release assets the scan missed, their files restored, and count them."""
|
||||
registered = load_gitignored_large_files(GITIGNORE)
|
||||
Database entries name paths relative to the tree holding bios/, and so
|
||||
does the registry of release assets in that tree's .gitignore.
|
||||
"""
|
||||
registered = load_gitignored_large_files(tree / ".gitignore")
|
||||
if not registered:
|
||||
return 0
|
||||
existing_db = read_database(db_path)
|
||||
if existing_db is None:
|
||||
return 0
|
||||
kept = surviving_entries(existing_db, files, registered)
|
||||
restore_release_assets(kept, registered, offline=offline)
|
||||
restore_release_assets(kept, registered, tree, offline=offline)
|
||||
files.update(kept)
|
||||
return len(kept)
|
||||
|
||||
@@ -44,10 +43,11 @@ def preserve_release_assets(files: dict, db_path: str, *, offline: bool) -> int:
|
||||
def generate(args: argparse.Namespace) -> int:
|
||||
"""Scan bios/ and write the database, 1 when a declared source or the old database cannot be read."""
|
||||
bios_dir = Path(args.bios_dir)
|
||||
cache_file = cache_path(bios_dir)
|
||||
|
||||
# A forced run rehashes every file but keeps the previous digests to
|
||||
# check the new ones against.
|
||||
cache = load_cache(CACHE_FILE)
|
||||
cache = load_cache(cache_file)
|
||||
|
||||
print(f"Scanning {bios_dir}/ ...")
|
||||
files, aliases, new_cache = scan_bios_dir(bios_dir, cache, args.force)
|
||||
@@ -57,7 +57,9 @@ def generate(args: argparse.Namespace) -> int:
|
||||
|
||||
# Preserve entries for large files stored as release assets (.gitignore)
|
||||
try:
|
||||
preserved = preserve_release_assets(files, args.output, offline=args.offline)
|
||||
preserved = preserve_release_assets(
|
||||
files, args.output, bios_dir.parent, offline=args.offline
|
||||
)
|
||||
except DatabaseUnreadable as exc:
|
||||
print(exc, file=sys.stderr)
|
||||
return 1
|
||||
@@ -89,7 +91,7 @@ def generate(args: argparse.Namespace) -> int:
|
||||
|
||||
written = write_database(args.output, database)
|
||||
|
||||
save_cache(CACHE_FILE, new_cache)
|
||||
save_cache(cache_file, new_cache)
|
||||
|
||||
alias_count = sum(len(v) for v in aliases.values())
|
||||
name_count = len(indexes["by_name"])
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
Usage:
|
||||
python scripts/generate_db.py [--force] [--bios-dir DIR] [--output FILE]
|
||||
|
||||
Supports incremental mode via .cache/db_cache.json (mtime-based).
|
||||
Supports incremental mode via .cache/db_cache.json beside the scanned
|
||||
tree (mtime-based).
|
||||
Use --force to rehash all files.
|
||||
"""
|
||||
|
||||
|
||||
Reference in new issue
Block a user