From ba692da94fa613f89267dbf3dec5fe314407cb22 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:44:56 +0100 Subject: [PATCH] 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. --- scripts/release/assets.py | 5 +++-- scripts/release/check.py | 4 ++-- scripts/release/restore.py | 7 ++++--- scripts/release/sync.py | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/release/assets.py b/scripts/release/assets.py index ead6d1b85..39a3cb59f 100644 --- a/scripts/release/assets.py +++ b/scripts/release/assets.py @@ -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 diff --git a/scripts/release/check.py b/scripts/release/check.py index 67b559dc5..fb80cd631 100644 --- a/scripts/release/check.py +++ b/scripts/release/check.py @@ -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]: diff --git a/scripts/release/restore.py b/scripts/release/restore.py index 75e6d9053..77330d1b4 100644 --- a/scripts/release/restore.py +++ b/scripts/release/restore.py @@ -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) diff --git a/scripts/release/sync.py b/scripts/release/sync.py index 10897c277..5c8ad762b 100644 --- a/scripts/release/sync.py +++ b/scripts/release/sync.py @@ -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]: