@@ -21,14 +21,29 @@ def parse_name(ckpt_name):
21
21
return filename
22
22
23
23
24
- def calculate_sha256 (file_path ):
25
- sha256_hash = hashlib .sha256 ()
24
+ def get_sha256 (file_path ):
25
+
26
+ file_no_ext = os .path .splitext (file_path )[0 ]
27
+ hash_file = file_no_ext + ".sha256"
28
+
29
+ if os .path .exists (hash_file ):
30
+ try :
31
+ with open (hash_file , "r" ) as f :
32
+ return f .read ().strip ()
33
+ except OSError as e :
34
+ print (f"comfy-image-saver: Error reading existing hash file: { e } " )
26
35
36
+ sha256_hash = hashlib .sha256 ()
27
37
with open (file_path , "rb" ) as f :
28
- # Read the file in chunks to avoid loading the entire file into memory
29
38
for byte_block in iter (lambda : f .read (4096 ), b"" ):
30
39
sha256_hash .update (byte_block )
31
40
41
+ try :
42
+ with open (hash_file , "w" ) as f :
43
+ f .write (sha256_hash .hexdigest ())
44
+ except OSError as e :
45
+ print (f"comfy-image-saver: Error writing hash to { hash_file } : { e } " )
46
+
32
47
return sha256_hash .hexdigest ()
33
48
34
49
@@ -355,7 +370,7 @@ def save_files(
355
370
)
356
371
357
372
ckpt_path = folder_paths .get_full_path ("checkpoints" , modelname )
358
- modelhash = calculate_sha256 (ckpt_path )[:10 ]
373
+ modelhash = get_sha256 (ckpt_path )[:10 ]
359
374
civitai_sampler_name = self .get_civitai_sampler_name (sampler_name , scheduler )
360
375
comment = f"{ handle_whitespace (positive )} \n Negative prompt: { handle_whitespace (negative )} \n Steps: { steps } , Sampler: { civitai_sampler_name } , CFG scale: { cfg } , Seed: { seed_value } , Size: { width } x{ height } , Model hash: { modelhash } , Model: { basemodelname } , Version: ComfyUI"
361
376
output_path = os .path .join (self .output_dir , path )
0 commit comments