Skip to content

Commit

Permalink
BUG: symlink dirs treated as files during indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpa committed Sep 16, 2024
1 parent 95c7aa9 commit cdd3bc8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions bids/layout/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ def _index_dir(self, path, config, force=None):
# Get lists of 1st-level subdirectories and files in the path directory
_, dirnames, filenames = next(path.fs.walk(path.path))

# Symbolic links are returned as filenames even if they point to directories
# Temporary list to store symbolic links that need to be removed from filenames
links_to_dirs = []

# Find directories in filenames
for possible_link in filenames:
full_path = path / possible_link
if full_path.is_dir():
links_to_dirs.append(possible_link)

Check warning on line 218 in bids/layout/index.py

View check run for this annotation

Codecov / codecov/patch

bids/layout/index.py#L218

Added line #L218 was not covered by tests

dirnames.extend(links_to_dirs)

for link in links_to_dirs:
filenames.remove(link)

Check warning on line 223 in bids/layout/index.py

View check run for this annotation

Codecov / codecov/patch

bids/layout/index.py#L223

Added line #L223 was not covered by tests

# Move any directories suffixed with .zarr to filenames
zarrnames = [entry for entry in dirnames if Path(entry).suffix == '.zarr']
dirnames = [entry for entry in dirnames if Path(entry).suffix != '.zarr']
Expand Down Expand Up @@ -332,7 +347,7 @@ def load_json(path):

to_store = (file_ents, payload, bf.path)
file_data[key][bf._dirname].append(to_store)

# To avoid integrity errors, track primary keys we've seen
seen_assocs = set()

Expand Down Expand Up @@ -494,7 +509,7 @@ def create_association_pair(src, dst, kind, kind2=None):
self.session.add(all_entities[md_key])
tag = _create_tag_dict(bf, all_entities[md_key], md_val, is_metadata=True)
all_tag_dicts.append(tag)

self.session.bulk_save_objects(all_objs)
self.session.bulk_insert_mappings(Tag, all_tag_dicts)
self.session.commit()
Expand Down

0 comments on commit cdd3bc8

Please sign in to comment.