Prevent duplicates of root folders when using symlinks

This commit is contained in:
Your Name
2025-04-19 21:42:01 +03:00
parent 64c9e4aeca
commit bbf7295c32

View File

@@ -99,21 +99,29 @@ class Config:
def _init_lora_paths(self) -> List[str]: def _init_lora_paths(self) -> List[str]:
"""Initialize and validate LoRA paths from ComfyUI settings""" """Initialize and validate LoRA paths from ComfyUI settings"""
paths = sorted(set(path.replace(os.sep, "/") raw_paths = folder_paths.get_folder_paths("loras")
for path in folder_paths.get_folder_paths("loras")
if os.path.exists(path)), key=lambda p: p.lower())
print("Found LoRA roots:", "\n - " + "\n - ".join(paths))
if not paths: # Normalize and resolve symlinks, store mapping from resolved -> original
path_map = {}
for path in raw_paths:
if os.path.exists(path):
real_path = os.path.normpath(os.path.realpath(path)).replace(os.sep, '/')
path_map[real_path] = path_map.get(real_path, path) # preserve first seen
# Now sort and use only the deduplicated real paths
unique_paths = sorted(path_map.values(), key=lambda p: p.lower())
print("Found LoRA roots:", "\n - " + "\n - ".join(unique_paths))
if not unique_paths:
raise ValueError("No valid loras folders found in ComfyUI configuration") raise ValueError("No valid loras folders found in ComfyUI configuration")
# 初始化路径映射 for original_path in unique_paths:
for path in paths: real_path = os.path.normpath(os.path.realpath(original_path)).replace(os.sep, '/')
real_path = os.path.normpath(os.path.realpath(path)).replace(os.sep, '/') if real_path != original_path:
if real_path != path: self.add_path_mapping(original_path, real_path)
self.add_path_mapping(path, real_path)
return unique_paths
return paths
def get_preview_static_url(self, preview_path: str) -> str: def get_preview_static_url(self, preview_path: str) -> str:
"""Convert local preview path to static URL""" """Convert local preview path to static URL"""