Skip to content

Fix iter_find_files depth with trailing path separators - #485

Closed
Yananix wants to merge 1 commit into
mahmoud:masterfrom
Yananix:fix/find-files-trailing-separator
Closed

Yananix wants to merge 1 commit into
mahmoud:masterfrom
Yananix:fix/find-files-trailing-separator

Conversation

@Yananix

@Yananix Yananix commented Sep 7, 2026 •

Copy link
Copy Markdown

A trailing path separator changes the results of iter_find_files when max_depth is set. With root.txt in a directory and child/child.txt below it, max_depth=0 correctly returns only root.txt for the directory path, but also returns child.txt when the same path ends in a separator. Multiple trailing separators let still deeper files through.

The depth calculation subtracts counts of separator-delimited components. Trailing empty components in the initial directory inflate the starting depth. Calculate depth from os.path.relpath(root, directory) instead, so equivalent directory spellings have the same limit.

The regression test builds a real three-level temporary tree and checks max_depth=0 and 1 with zero, one, and two trailing separators. It fails before the fix and passes after it.

Validation on macOS, Python 3.12.13:

  • python -m pytest --doctest-modules boltons tests -q: 673 passed.
  • git diff --check passed.

mahmoud added a commit that referenced this pull request Oct 25, 2026
…micSaver cleanup, root-home shrinkuser, non-identifier names; include docs in sdist (#484, #518, #485, #539, #504, #573, #557)
@mahmoud

mahmoud commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Folded into #609 (see the PR description for credit). Thanks for the report and the repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants