From 04ce040d28b20dc6b42189f84dbe0c38ba8d86d7 Mon Sep 17 00:00:00 2001 From: doctorpangloss <@hiddenswitch.com> Date: Thu, 8 Feb 2024 09:30:16 -0800 Subject: [PATCH] Fix commonpath / using arg.cwd on Windows --- comfy/app/user_manager.py | 6 ++++-- comfy/client/embedded_comfy_client.py | 2 +- comfy/cmd/folder_paths.py | 7 ++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/comfy/app/user_manager.py b/comfy/app/user_manager.py index b5cf84c89..8e2bc76a0 100644 --- a/comfy/app/user_manager.py +++ b/comfy/app/user_manager.py @@ -2,6 +2,8 @@ import json import os import re import uuid +from typing import Optional + from aiohttp import web from ..cli_args import args from ..cmd.folder_paths import user_directory @@ -50,7 +52,7 @@ class UserManager(): # prevent leaving /{type} if os.path.commonpath((root_dir, user_root)) != root_dir: - return None + raise PermissionError() parent = user_root @@ -58,7 +60,7 @@ class UserManager(): # prevent leaving /{type}/{user} path = os.path.abspath(os.path.join(user_root, file)) if os.path.commonpath((user_root, path)) != user_root: - return None + raise PermissionError() if create_dir and not os.path.exists(parent): os.mkdir(parent) diff --git a/comfy/client/embedded_comfy_client.py b/comfy/client/embedded_comfy_client.py index 31482bf18..c3e7a54b1 100644 --- a/comfy/client/embedded_comfy_client.py +++ b/comfy/client/embedded_comfy_client.py @@ -45,7 +45,7 @@ class EmbeddedComfyClient: async with EmbeddedComfyClient() as client: outputs = await client.queue_prompt(prompt) - print(result) + print(outputs) ``` """ diff --git a/comfy/cmd/folder_paths.py b/comfy/cmd/folder_paths.py index 26fff0a59..e27770c08 100644 --- a/comfy/cmd/folder_paths.py +++ b/comfy/cmd/folder_paths.py @@ -11,13 +11,14 @@ folder_names_and_paths = {} if 'main.py' in sys.argv: base_path = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../..")) -elif args.cwd: +elif args.cwd is not None: if not os.path.exists(args.cwd): try: - os.makedirs(args.cwd) + os.makedirs(args.cwd, exist_ok=True) except: print("Failed to create custom working directory") - base_path = args.cwd + # wrap the path to prevent slashedness from glitching out common path checks + base_path = os.path.realpath(args.cwd) else: base_path = os.getcwd() models_dir = os.path.join(base_path, "models")