refactor: release tools read file_digest

core.hashing.file_digest is the streamed loop the release tools carried,
byte for byte: 1 MiB reads, read again each call. It replaces
compute_hashes with cache=False there.
This commit is contained in:
Abdessamad Derraz committed 2026-11-18 20:44:56 +01:00
1 parent 27bff61560
commit ba692da94f
4 files changed
+11 -9

No files matched your search

+4 -3
View File
@@ -6,9 +6,10 @@ import contextlib
import os
import sys
import tempfile
from pathlib import Path
from core.artifacts import copy_file_atomic, set_plain_mode
from core.hashing import compute_hashes
from core.hashing import file_digest
from model.database import load_database
@@ -36,7 +37,7 @@ def index_cache(cache_dir: str) -> dict[str, str]:
path = os.path.join(cache_dir, name)
if not os.path.isfile(path):
continue
index[compute_hashes(path, frozenset({"sha1"}), cache=False)["sha1"]] = path
index[file_digest(Path(path))] = path
return index
@@ -55,7 +56,7 @@ def _copy_verified(source: str, path: str, sha1: str) -> bool:
os.close(handle)
try:
copy_file_atomic(source, scratch)
if compute_hashes(scratch, frozenset({"sha1"}), cache=False)["sha1"] != sha1:
if file_digest(Path(scratch)) != sha1:
print(f"Changed in the cache while restoring: {source}", file=sys.stderr)
return False
set_plain_mode(scratch)