fix hashing

This commit is contained in:
Vladimir Mandic
2023-08-23 07:26:57 +00:00
parent 863fa38c24
commit 3d1bcf88a2
2 changed files with 4 additions and 2 deletions
+3 -1
View File
@@ -32,11 +32,11 @@ def calculate_sha256(filename):
def sha256_from_cache(filename, title, use_addnet_hash=False):
hashes = cache("hashes-addnet") if use_addnet_hash else cache("hashes")
ondisk_mtime = os.path.getmtime(filename)
if title not in hashes:
return None
cached_sha256 = hashes[title].get("sha256", None)
cached_mtime = hashes[title].get("mtime", 0)
ondisk_mtime = os.path.getmtime(filename) if os.path.isfile(filename) else 0
if ondisk_mtime > cached_mtime or cached_sha256 is None:
return None
return cached_sha256
@@ -49,6 +49,8 @@ def sha256(filename, title, use_addnet_hash=False):
return sha256_value
if shared.cmd_opts.no_hashing:
return None
if not os.path.isfile(filename):
return None
if use_addnet_hash:
with progress.open(filename, 'rb', description=f'Calculating model hash: [cyan]{filename}', auto_refresh=True) as f:
sha256_value = addnet_hash_safetensors(f)