Fix commonpath / using arg.cwd on Windows

This commit is contained in:
doctorpangloss 2024-02-08 09:30:16 -08:00
parent 8508a5a853
commit 04ce040d28
3 changed files with 9 additions and 6 deletions

View File

@ -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)

View File

@ -45,7 +45,7 @@ class EmbeddedComfyClient:
async with EmbeddedComfyClient() as client:
outputs = await client.queue_prompt(prompt)
print(result)
print(outputs)
```
"""

View File

@ -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")