Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -95,15 +95,15 @@ 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()
file.seek(0x100000)
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
Expand Down
Loading