From 68fe47c0e86874cfeca2164a3cd2ae6a477d6c9b Mon Sep 17 00:00:00 2001 From: rgthree Date: Mon, 10 Nov 2025 23:55:04 -0500 Subject: [PATCH] Resolve symlinks (and userdirs) when looking for lora files reported by ComfyUI. Addresses #574 --- py/server/routes_model_info.py | 5 ++--- py/server/utils_info.py | 6 +++--- py/utils.py | 6 ++++++ pyproject.toml | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/py/server/routes_model_info.py b/py/server/routes_model_info.py index 4c7a130..61feb4d 100644 --- a/py/server/routes_model_info.py +++ b/py/server/routes_model_info.py @@ -6,7 +6,7 @@ from ..log import log from server import PromptServer import folder_paths -from ..utils import path_exists +from ..utils import abspath, path_exists from .utils_server import get_param, is_param_falsy from .utils_info import delete_model_info, get_model_info, set_model_info_partial, get_file_info @@ -159,8 +159,7 @@ async def api_get_models_info_img(request): file_param = get_param(request, 'file') file_path = folder_paths.get_full_path(model_type, file_param) if not path_exists(file_path): - file_path = os.path.abspath(file_path) - + file_path = abspath(file_path) img_path = None for ext in ['jpg', 'png', 'jpeg']: try_path = f'{os.path.splitext(file_path)[0]}.{ext}' diff --git a/py/server/utils_info.py b/py/server/utils_info.py index 1d3af9f..5b5963d 100644 --- a/py/server/utils_info.py +++ b/py/server/utils_info.py @@ -9,7 +9,7 @@ import requests from server import PromptServer import folder_paths -from ..utils import get_dict_value, load_json_file, file_exists, remove_path, save_json_file +from ..utils import abspath, get_dict_value, load_json_file, file_exists, remove_path, save_json_file from ..utils_userdata import read_userdata_json, save_userdata_json, delete_userdata_file @@ -414,8 +414,8 @@ def _read_file_metadata_from_header(file_path: str) -> dict: def get_folder_path(file: str, model_type) -> str | None: """Gets the file path ensuring it exists.""" file_path = folder_paths.get_full_path(model_type, file) - if file_path and not file_exists(file_path): - file_path = os.path.abspath(file_path) + if not file_exists(file_path): + filepath = abspath(file_path) if not file_exists(file_path): file_path = None return file_path diff --git a/py/utils.py b/py/utils.py index f282cc6..55bcf26 100644 --- a/py/utils.py +++ b/py/utils.py @@ -150,6 +150,12 @@ def remove_path(path): return True return False +def abspath(file_path: str): + """Resolves the abspath of a file, resolving symlinks and user dirs.""" + if not path_exists(file_path): + maybe_path = os.path.abspath(os.path.realpath(os.path.expanduser(file_path))) + file_path = maybe_path if path_exists(maybe_path) else file_path + return file_path class ByPassTypeTuple(tuple): """A special class that will return additional "AnyType" strings beyond defined values. diff --git a/pyproject.toml b/pyproject.toml index 82a65dd..2cad497 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "rgthree-comfy" description = "Making ComfyUI more comfortable." -version = "1.0.2511091959" +version = "1.0.2511102355" license = { file = "LICENSE" } dependencies = []