Skip to content

Commit 11b7cae

Browse files
committed
warning WebUI is installed under a dot directory
1 parent 984b952 commit 11b7cae

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

webui.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,40 @@ def api_only():
4545
)
4646

4747

48+
def warning_if_invalid_install_dir():
49+
"""
50+
Shows a warning if the webui is installed under a path that contains a leading dot in any of its parent directories.
51+
52+
Gradio '/file=' route will block access to files that have a leading dot in the path segments.
53+
We use this route to serve files such as JavaScript and CSS to the webpage,
54+
if those files are blocked, the webpage will not function properly.
55+
See https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13292
56+
57+
This is a security feature was added to Gradio 3.32.0 and is removed in later versions,
58+
this check should be removed when it's no longer applicable.
59+
"""
60+
from pathlib import Path
61+
62+
def abspath(path):
63+
"""modified from Gradio 3.41.2 gradio.utils.abspath()"""
64+
if path.is_absolute():
65+
return path
66+
is_symlink = path.is_symlink() or any(parent.is_symlink() for parent in path.parents)
67+
if is_symlink or path == path.resolve():
68+
return Path.cwd() / path
69+
else:
70+
return path.resolve()
71+
webui_root = Path(__file__).parent
72+
if any(part.startswith(".") for part in abspath(webui_root).parts):
73+
print(f'''{"!"*25} Warning {"!"*25}
74+
WebUI is installed in a directory that has a leading dot (.) in one of its parent directories.
75+
This will prevent WebUI from functioning properly.
76+
Please move the installation to a different directory.
77+
Current path: "{webui_root}"
78+
For more information see: https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13292
79+
{"!"*25} Warning {"!"*25}''')
80+
81+
4882
def webui():
4983
from modules.shared_cmd_options import cmd_opts
5084

@@ -53,6 +87,8 @@ def webui():
5387

5488
from modules import shared, ui_tempdir, script_callbacks, ui, progress, ui_extra_networks
5589

90+
warning_if_invalid_install_dir()
91+
5692
while 1:
5793
if shared.opts.clean_temp_dir_at_start:
5894
ui_tempdir.cleanup_tmpdr()

0 commit comments

Comments
 (0)