From 744d56261b0ad30e8cbd9f153ec23b890f2d5bce Mon Sep 17 00:00:00 2001 From: samith Date: Sat, 4 Jul 2026 21:30:39 +0530 Subject: [PATCH 1/3] fix: enhance path validation and redirection for model directories --- folder_paths.py | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/folder_paths.py b/folder_paths.py index ee048b0f2df6..09522e19ea48 100644 --- a/folder_paths.py +++ b/folder_paths.py @@ -4,7 +4,7 @@ import logging from typing import Literal, List from collections.abc import Collection - +import json from comfy.cli_args import args supported_pt_extensions: set[str] = {'.ckpt', '.pt', '.pt2', '.bin', '.pth', '.safetensors', '.pkl', '.sft'} @@ -13,11 +13,39 @@ # --base-directory - Resets all default paths configured in folder_paths with a new base path if args.base_directory: - base_path = os.path.abspath(args.base_directory) + raw_path = os.path.abspath(args.base_directory) else: - base_path = os.path.dirname(os.path.realpath(__file__)) + raw_path = os.path.dirname(os.path.realpath(__file__)) + + +def valid_path(saved_path,description = "Instance Folder"): + if os.path.exists(saved_path): + return saved_path + + redirect_path = os.path.join(os.path.dirname(__file__),"path.redirects.json") + if os.path.exists(redirect_path): + with open("redirect_path","r") as f: + redirects = json.load(f) + if description in redirects and os.path.exists(redirects[description]): + return redirects[description] + print(f"\n[!] ALERT: {description} not found at: {saved_path}") + new_path= input(f"Please paste the updated absolute path for '{description}': ").strip() + try: + redirects = {} + if os.path.exists(redirects): + with open(redirects, "r") as f: redirects = json.load(f) + redirects[description] = new_path + with open(redirects, "w") as f: json.dump(redirects, f, indent=4) + except Exception: + pass + + return new_path + + + +base_path = valid_path(raw_path,description = "ComfyUI Core Directory") -models_dir = os.path.join(base_path, "models") +models_dir =valid_path( os.path.join(base_path,"models"),description = "Model Directory") folder_names_and_paths["checkpoints"] = ([os.path.join(models_dir, "checkpoints")], supported_pt_extensions) folder_names_and_paths["configs"] = ([os.path.join(models_dir, "configs")], [".yaml"]) @@ -60,7 +88,7 @@ folder_names_and_paths["detection"] = ([os.path.join(models_dir, "detection")], supported_pt_extensions) -output_directory = os.path.join(base_path, "output") +output_directory =valid_path( os.path.join(base_path, "output"),"Output Directory") temp_directory = os.path.join(base_path, "temp") input_directory = os.path.join(base_path, "input") user_directory = os.path.join(base_path, "user") From a2b56d8c1fc0b81e2574a3b938db4523e2d16107 Mon Sep 17 00:00:00 2001 From: samith Date: Sat, 4 Jul 2026 21:46:12 +0530 Subject: [PATCH 2/3] fix: correct file path for loading redirects in valid_path function --- folder_paths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/folder_paths.py b/folder_paths.py index 09522e19ea48..f7faf84bd2bf 100644 --- a/folder_paths.py +++ b/folder_paths.py @@ -24,7 +24,7 @@ def valid_path(saved_path,description = "Instance Folder"): redirect_path = os.path.join(os.path.dirname(__file__),"path.redirects.json") if os.path.exists(redirect_path): - with open("redirect_path","r") as f: + with open(redirect_path,"r") as f: redirects = json.load(f) if description in redirects and os.path.exists(redirects[description]): return redirects[description] From 3c3d7feefe9ce37fa8467c0bfcb7750a4d86b705 Mon Sep 17 00:00:00 2001 From: samith Date: Sat, 4 Jul 2026 22:03:02 +0530 Subject: [PATCH 3/3] Update folder_paths.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- folder_paths.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/folder_paths.py b/folder_paths.py index f7faf84bd2bf..5cc9f8ecf8c9 100644 --- a/folder_paths.py +++ b/folder_paths.py @@ -30,14 +30,13 @@ def valid_path(saved_path,description = "Instance Folder"): return redirects[description] print(f"\n[!] ALERT: {description} not found at: {saved_path}") new_path= input(f"Please paste the updated absolute path for '{description}': ").strip() - try: - redirects = {} - if os.path.exists(redirects): - with open(redirects, "r") as f: redirects = json.load(f) - redirects[description] = new_path - with open(redirects, "w") as f: json.dump(redirects, f, indent=4) - except Exception: - pass + redirects = {} + if os.path.exists(redirect_path): + with open(redirect_path, "r") as f: + redirects = json.load(f) + redirects[description] = new_path + with open(redirect_path, "w") as f: + json.dump(redirects, f, indent=4) return new_path