allow symbolic links to be followed during autoimport (#4268)

## What type of PR is this? (check all applicable)

- [X] Feature
- [X] Bug Fix

## Have you discussed this change with the InvokeAI team?
- [X] Yes

## Have you updated all relevant documentation?
- [X] Yes

## Description

Follow symbolic links when auto importing from a directory. Previously
links to files worked, but links to directories weren’t entered during
the scanning/import process.
This commit is contained in:
Lincoln Stein 2023-08-17 20:31:00 -04:00 committed by GitHub
commit 498d2ecc2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View File

@ -116,7 +116,7 @@ class MigrateTo3(object):
appropriate location within the destination models directory. appropriate location within the destination models directory.
""" """
directories_scanned = set() directories_scanned = set()
for root, dirs, files in os.walk(src_dir): for root, dirs, files in os.walk(src_dir, followlinks=True):
for d in dirs: for d in dirs:
try: try:
model = Path(root, d) model = Path(root, d)

View File

@ -56,7 +56,7 @@ class ModelSearch(ABC):
self.on_search_completed() self.on_search_completed()
def walk_directory(self, path: Path): def walk_directory(self, path: Path):
for root, dirs, files in os.walk(path): for root, dirs, files in os.walk(path, followlinks=True):
if str(Path(root).name).startswith("."): if str(Path(root).name).startswith("."):
self._pruned_paths.add(root) self._pruned_paths.add(root)
if any([Path(root).is_relative_to(x) for x in self._pruned_paths]): if any([Path(root).is_relative_to(x) for x in self._pruned_paths]):

View File

@ -89,7 +89,7 @@ def get_image_paths(dataroot):
def _get_paths_from_images(path): def _get_paths_from_images(path):
assert os.path.isdir(path), "{:s} is not a valid directory".format(path) assert os.path.isdir(path), "{:s} is not a valid directory".format(path)
images = [] images = []
for dirpath, _, fnames in sorted(os.walk(path)): for dirpath, _, fnames in sorted(os.walk(path, followlinks=True)):
for fname in sorted(fnames): for fname in sorted(fnames):
if is_image_file(fname): if is_image_file(fname):
img_path = os.path.join(dirpath, fname) img_path = os.path.join(dirpath, fname)