mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-07 21:00:49 +08:00
add argument to skip symlink scan
This commit is contained in:
parent
135fa49ec2
commit
02064cb6e5
@ -117,10 +117,27 @@ class ModelFileManager:
|
|||||||
# TODO use settings
|
# TODO use settings
|
||||||
include_hidden_files = False
|
include_hidden_files = False
|
||||||
|
|
||||||
|
# Check if we should skip following symlinks
|
||||||
|
from comfy.cli_args import args
|
||||||
|
skip_symlinks = getattr(args, 'skip_symlink_scan', False)
|
||||||
|
followlinks = not skip_symlinks
|
||||||
|
|
||||||
result: list[str] = []
|
result: list[str] = []
|
||||||
dirs: dict[str, float] = {}
|
dirs: dict[str, float] = {}
|
||||||
|
|
||||||
for dirpath, subdirs, filenames in os.walk(directory, followlinks=True, topdown=True):
|
for dirpath, subdirs, filenames in os.walk(directory, followlinks=followlinks, topdown=True):
|
||||||
|
# If skipping symlinks, filter out symlinked directories
|
||||||
|
if skip_symlinks:
|
||||||
|
filtered_subdirs = []
|
||||||
|
for d in subdirs:
|
||||||
|
subdir_path = os.path.join(dirpath, d)
|
||||||
|
# Check if it's a symlink
|
||||||
|
if os.path.islink(subdir_path):
|
||||||
|
logging.debug(f"Skipping symlink: {subdir_path}")
|
||||||
|
continue
|
||||||
|
filtered_subdirs.append(d)
|
||||||
|
subdirs[:] = filtered_subdirs
|
||||||
|
|
||||||
subdirs[:] = [d for d in subdirs if d not in excluded_dir_names]
|
subdirs[:] = [d for d in subdirs if d not in excluded_dir_names]
|
||||||
if not include_hidden_files:
|
if not include_hidden_files:
|
||||||
subdirs[:] = [d for d in subdirs if not d.startswith(".")]
|
subdirs[:] = [d for d in subdirs if not d.startswith(".")]
|
||||||
|
|||||||
@ -216,6 +216,8 @@ database_default_path = os.path.abspath(
|
|||||||
)
|
)
|
||||||
parser.add_argument("--database-url", type=str, default=f"sqlite:///{database_default_path}", help="Specify the database URL, e.g. for an in-memory database you can use 'sqlite:///:memory:'.")
|
parser.add_argument("--database-url", type=str, default=f"sqlite:///{database_default_path}", help="Specify the database URL, e.g. for an in-memory database you can use 'sqlite:///:memory:'.")
|
||||||
|
|
||||||
|
parser.add_argument("--skip-symlink-scan", action="store_true", help="Skip following symlinks when scanning directories. Useful when symlinks point to network paths with many files. Specifying a filename directly will still work.")
|
||||||
|
|
||||||
if comfy.options.args_parsing:
|
if comfy.options.args_parsing:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -240,6 +240,10 @@ def recursive_search(directory: str, excluded_dir_names: list[str] | None=None)
|
|||||||
if excluded_dir_names is None:
|
if excluded_dir_names is None:
|
||||||
excluded_dir_names = []
|
excluded_dir_names = []
|
||||||
|
|
||||||
|
# Check if we should skip following symlinks
|
||||||
|
skip_symlinks = getattr(args, 'skip_symlink_scan', False)
|
||||||
|
followlinks = not skip_symlinks
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
dirs = {}
|
dirs = {}
|
||||||
|
|
||||||
@ -254,7 +258,19 @@ def recursive_search(directory: str, excluded_dir_names: list[str] | None=None)
|
|||||||
subdirs: list[str]
|
subdirs: list[str]
|
||||||
filenames: list[str]
|
filenames: list[str]
|
||||||
|
|
||||||
for dirpath, subdirs, filenames in os.walk(directory, followlinks=True, topdown=True):
|
for dirpath, subdirs, filenames in os.walk(directory, followlinks=followlinks, topdown=True):
|
||||||
|
# If skipping symlinks, filter out symlinked directories
|
||||||
|
if skip_symlinks:
|
||||||
|
filtered_subdirs = []
|
||||||
|
for d in subdirs:
|
||||||
|
subdir_path = os.path.join(dirpath, d)
|
||||||
|
# Check if it's a symlink
|
||||||
|
if os.path.islink(subdir_path):
|
||||||
|
logging.debug(f"Skipping symlink: {subdir_path}")
|
||||||
|
continue
|
||||||
|
filtered_subdirs.append(d)
|
||||||
|
subdirs[:] = filtered_subdirs
|
||||||
|
|
||||||
subdirs[:] = [d for d in subdirs if d not in excluded_dir_names]
|
subdirs[:] = [d for d in subdirs if d not in excluded_dir_names]
|
||||||
for file_name in filenames:
|
for file_name in filenames:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user