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
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ New features:

Bug fixes:

- Avoid following symbolic link targets when checking file types in ``iter_tree_files(follow_links=False)``.

- Honor `on_error` when opening a directory fails during tree traversal.

- `Pull #123`_: Ignore invalid gitignore bracket ranges for `GitIgnoreSpec`.
Expand Down
2 changes: 2 additions & 0 deletions CHANGES_1.in.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ New features:

Bug fixes:

- Avoid following symbolic link targets when checking file types in ``iter_tree_files(follow_links=False)``.

- Honor `on_error` when opening a directory fails during tree traversal.

- `Pull #123`_: Ignore invalid gitignore bracket ranges for `GitIgnoreSpec`.
Expand Down
2 changes: 2 additions & 0 deletions README-dist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ Major changes:

Bug fixes:

- Avoid following symbolic link targets when checking file types in ``iter_tree_files(follow_links=False)``.

- `Pull #123`_: Ignore invalid gitignore bracket ranges for `GitIgnoreSpec`.


Expand Down
2 changes: 1 addition & 1 deletion pathspec/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def _iter_tree_files_next(
# files.
yield from _iter_tree_files_next(root_full, node_rel, memo, on_error, follow_links)

elif node_ent.is_file():
elif node_ent.is_file(follow_symlinks=follow_links):
# Child node is a file, yield it.
yield node_rel

Expand Down
25 changes: 25 additions & 0 deletions tests/test_01_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,31 @@ def test_02_link_8_no_follow_links_2_files(self):
'DirX',
])))

def test_02_link_9_no_follow_loop_links_2_files(self):
"""
Unfollowed links with cyclic targets are yielded without inspecting targets.
"""
self.require_symlink()
for case, links in [
('Self', [('Loop', 'Loop')]),
('Pair', [('First', 'Second'), ('Second', 'First')]),
]:
with self.subTest(case=case):
self.make_dirs([case, f'{case}/Dir'])
self.make_files([f'{case}/kept.txt', f'{case}/Dir/child.txt'])
self.make_links([
(f'{case}/{link}', f'{case}/{target}')
for link, target in links
])
errors = []
results = set(iter_tree_files(
self.temp_dir / case, follow_links=False, on_error=errors.append,
))
self.assertEqual(results, {
'kept.txt', ospath('Dir/child.txt'), *[link for link, _ in links],
})
self.assertEqual(errors, [])

def test_03_subdir_1_from_filesystem_root(self):
"""
raverse only the requested subtree when the root ends in a separator.
Expand Down