mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-25 02:57:52 -06:00
refactor: read data/.versions.json in one place
This commit is contained in:
1 parent
67cb99606d
commit
82d3f595de
5 files changed
+14
-32
No files matched your search
@@ -15,7 +15,7 @@ import zipfile
|
||||
from collections.abc import Callable, Iterator
|
||||
from pathlib import Path
|
||||
|
||||
from core.artifacts import file_lock as _file_lock, set_plain_mode
|
||||
from core.artifacts import file_lock as _file_lock, write_text_atomic
|
||||
from core.github import github_token
|
||||
from model.registry import VERSIONS_FILE, load_versions
|
||||
|
||||
@@ -113,24 +113,10 @@ def _save_versions(
|
||||
"""Write the version file whole or not at all.
|
||||
|
||||
Truncating in place let a concurrent reader load an empty file and die
|
||||
on JSONDecodeError. The scratch file sits beside the target so the
|
||||
rename stays on one filesystem.
|
||||
on JSONDecodeError.
|
||||
"""
|
||||
path = Path(versions_path)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
handle, scratch = tempfile.mkstemp(
|
||||
dir=path.parent, prefix=f".{path.name}.", suffix=".tmp"
|
||||
)
|
||||
try:
|
||||
with os.fdopen(handle, "w") as f:
|
||||
json.dump(versions, f, indent=2, sort_keys=True)
|
||||
f.write("\n")
|
||||
set_plain_mode(scratch)
|
||||
os.replace(scratch, path)
|
||||
except BaseException:
|
||||
with contextlib.suppress(OSError):
|
||||
os.unlink(scratch)
|
||||
raise
|
||||
Path(versions_path).parent.mkdir(parents=True, exist_ok=True)
|
||||
write_text_atomic(versions_path, json.dumps(versions, indent=2, sort_keys=True) + "\n")
|
||||
|
||||
|
||||
def _record_version(key: str, record: dict, versions_path: str) -> None:
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import zipfile
|
||||
@@ -13,6 +12,7 @@ from typing import TYPE_CHECKING, TypedDict
|
||||
from core.hashing import compute_hashes
|
||||
from core.options import reject_unknown
|
||||
from model.declarations import declared_root
|
||||
from model.registry import load_versions
|
||||
from model.profiles import entry_system_ids, installed_data_refs
|
||||
from model.systems import norm_system_id
|
||||
from packs.archive import PackRecord, Placed, add_pack_member
|
||||
@@ -340,10 +340,7 @@ def _recorded_version(ref: str, entry: dict, versions: dict[str, dict[str, dict]
|
||||
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)] = {}
|
||||
versions[str(recorded)] = load_versions(recorded)
|
||||
found = versions[str(recorded)].get(ref)
|
||||
return found if isinstance(found, dict) else {}
|
||||
|
||||
|
||||
Reference in new issue
Block a user