File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ def addnet_hash_safetensors(b):
8383 return hash_sha256 .hexdigest ()
8484
8585
86- def partial_hash_from_cache (filename , ignore_cache = False ):
86+ def partial_hash_from_cache (filename , * , ignore_cache : bool = False , digits : int = 8 ):
8787 """old hash that only looks at a small part of the file and is prone to collisions
8888 kept for compatibility, don't use this for new things
8989 """
@@ -95,15 +95,15 @@ def partial_hash_from_cache(filename, ignore_cache=False):
9595 cache_mtime = cache_entry .get ("mtime" , 0 )
9696 cache_hash = cache_entry .get ("hash" , None )
9797 if mtime == cache_mtime and cache_hash and not ignore_cache :
98- return cache_hash
98+ return cache_hash [ 0 : digits ]
9999
100100 with open (filename , 'rb' ) as file :
101101 m = hashlib .sha256 ()
102102 file .seek (0x100000 )
103103 m .update (file .read (0x10000 ))
104104 partial_hash = m .hexdigest ()
105105 hashes [filename ] = {'mtime' : mtime , 'hash' : partial_hash }
106- return partial_hash [0 :8 ]
106+ return partial_hash [0 :digits ]
107107
108108 except FileNotFoundError :
109109 pass
You can’t perform that action at this time.
0 commit comments