fix: check a forced rehash against the last one

The pipeline rebuilds the database with --force, which discarded the previous digests and wrote whatever the CPU computed, on a host that has given an incorrect SHA-1 under load. The forced run still rehashes every file, but a digest that contradicts the cache for an unchanged mtime and size is computed again, and the two readings that agree win, with a warning naming the file.
This commit is contained in:
Abdessamad Derraz committed 2026-10-20 03:24:55 +02:00
1 parent ab1f5d7eb4
commit c7c2f260f3
3 files changed
+68 -3

No files matched your search

+7 -1
View File
@@ -24,9 +24,15 @@ _hash_cache: dict[tuple, dict[str, str]] = {}
def compute_hashes(
filepath: str | Path,
algorithms: frozenset[str] | None = None,
cache: bool = True,
) -> dict[str, str]:
"""Compute file hashes. Pass *algorithms* to limit which are computed."""
"""Compute file hashes. Pass *algorithms* to limit which are computed.
cache=False reads the file again, for a second opinion on a digest.
"""
algos = frozenset(algorithms) if algorithms else _ALL_ALGORITHMS
if not cache:
return _compute_hashes(filepath, algos)
try:
stat = os.stat(filepath)
key: tuple | None = (