From 32595360f22c86ee02bbcb492b0029d2b31e1344 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Sat, 15 Feb 2025 23:49:48 +0800 Subject: [PATCH] fix old hash digits (#16845) --- modules/hashes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/hashes.py b/modules/hashes.py index 265885669..c3be5a007 100644 --- a/modules/hashes.py +++ b/modules/hashes.py @@ -83,7 +83,7 @@ def addnet_hash_safetensors(b): return hash_sha256.hexdigest() -def partial_hash_from_cache(filename, ignore_cache=False): +def partial_hash_from_cache(filename, *, ignore_cache: bool = False, digits: int = 8): """old hash that only looks at a small part of the file and is prone to collisions kept for compatibility, don't use this for new things """ @@ -95,7 +95,7 @@ def partial_hash_from_cache(filename, ignore_cache=False): cache_mtime = cache_entry.get("mtime", 0) cache_hash = cache_entry.get("hash", None) if mtime == cache_mtime and cache_hash and not ignore_cache: - return cache_hash + return cache_hash[0:digits] with open(filename, 'rb') as file: m = hashlib.sha256() @@ -103,7 +103,7 @@ def partial_hash_from_cache(filename, ignore_cache=False): m.update(file.read(0x10000)) partial_hash = m.hexdigest() hashes[filename] = {'mtime': mtime, 'hash': partial_hash} - return partial_hash[0:8] + return partial_hash[0:digits] except FileNotFoundError: pass