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

+3 -2
View File
@@ -7,9 +7,10 @@ import os
import re
import subprocess
from collections.abc import Iterable
from pathlib import Path
from typing import NamedTuple
from core.hashing import compute_hashes
from core.hashing import file_digest
from model.composition import composition_tier
from model.largefiles import LARGE_FILES_RELEASE, LARGE_FILES_REPO, asset_names, registered_paths
@@ -268,7 +269,7 @@ def cache_hashes(names: set[str], cache_dir: str = ".cache/large") -> dict[str,
for name in names:
path = os.path.join(cache_dir, name)
if os.path.isfile(path):
hashes[name] = compute_hashes(path, frozenset({"sha1"}), cache=False)["sha1"]
hashes[name] = file_digest(Path(path))
return hashes
+2 -2
View File
@@ -7,7 +7,7 @@ import subprocess
from dataclasses import dataclass
from pathlib import Path
from core.hashing import compute_hashes
from core.hashing import file_digest
from release.assets import digests_of
from model.largefiles import LARGE_FILES_REPO
@@ -114,7 +114,7 @@ def compare_release(
def _sha256(path: Path) -> str:
return compute_hashes(path, frozenset({"sha256"}), cache=False)["sha256"]
return file_digest(path, "sha256")
def fetch_assets(tag: str) -> tuple[dict[str, Asset], bool]:
+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)
+2 -2
View File
@@ -9,7 +9,7 @@ from collections.abc import Callable
from dataclasses import dataclass
from pathlib import Path
from core.hashing import compute_hashes
from core.hashing import file_digest
from model.largefiles import LARGE_FILES_RELEASE, LARGE_FILES_REPO, asset_names, registered_paths
from release.assets import compare, expected_assets, expected_digests, fetch_release
@@ -28,7 +28,7 @@ class Upload:
def sha1_of(path: Path) -> str:
return compute_hashes(path, frozenset({"sha1"}), cache=False)["sha1"]
return file_digest(path)
def database_sha1(db: dict) -> dict[str, str]: