Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion app/model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,27 @@ def recursive_search_models_(self, directory: str, pathIndex: int) -> tuple[list
# TODO use settings
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] = []
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]
if not include_hidden_files:
subdirs[:] = [d for d in subdirs if not d.startswith(".")]
Expand Down
2 changes: 2 additions & 0 deletions comfy/cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def is_valid_directory(path: str) -> str:
)
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:
args = parser.parse_args()
else:
Expand Down
18 changes: 17 additions & 1 deletion folder_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ def recursive_search(directory: str, excluded_dir_names: list[str] | None=None)
if excluded_dir_names is None:
excluded_dir_names = []

# Check if we should skip following symlinks
skip_symlinks = getattr(args, 'skip_symlink_scan', False)
followlinks = not skip_symlinks

result = []
dirs = {}

Expand All @@ -254,7 +258,19 @@ def recursive_search(directory: str, excluded_dir_names: list[str] | None=None)
subdirs: 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]
for file_name in filenames:
try:
Expand Down