Skip to content

fix: FileFilter must check exclude_dirs before the endswith shortcut#2989

Open
LeSingh1 wants to merge 1 commit into
Kludex:mainfrom
LeSingh1:fix/file-filter-exclude-dirs-before-endswith
Open

fix: FileFilter must check exclude_dirs before the endswith shortcut#2989
LeSingh1 wants to merge 1 commit into
Kludex:mainfrom
LeSingh1:fix/file-filter-exclude-dirs-before-endswith

Conversation

@LeSingh1

Copy link
Copy Markdown

When an explicit path (e.g. .dotted or ext/ext.jpg) is listed in
--reload-include, FileFilter.__call__ matched via path.match()
and then hit the str(path).endswith(include_pattern) shortcut, which
returned True immediately. The early return skipped the loop that
checks exclude_dirs, so any file whose name exactly matched an include
pattern was watched even when it lived inside a directory listed in
--reload-exclude.

The endswith shortcut was added in c55af77 to let hidden/dotted files
and other non-glob entries bypass the pattern-level excludes (e.g.
.*). That intent is correct; the mistake is that it also bypassed
directory-level excludes, which is a stronger signal from the user.

The fix moves the exclude_dirs loop above the endswith shortcut so
that directory exclusions are always evaluated first. Files that match
an exact include pattern but reside under an excluded directory are now
rejected, while files outside excluded directories continue to bypass
the pattern excludes as before.

A new unit test (pure FileFilter instantiation, no file-system
watcher) reproduces the bug and confirms the fix: it asserts that
vendor/.dotted is not watched when .dotted is in --reload-include
and vendor/ is in --reload-exclude.

When an explicit path (no wildcards) is listed in --reload-include,
FileFilter.__call__ hit the str(path).endswith(include_pattern) branch
and returned True immediately, without checking whether the file lives
inside a directory listed in --reload-exclude.  The directory exclusion
was therefore silently bypassed for any non-glob include pattern.

Moving the exclude_dirs loop above the endswith shortcut preserves the
original intent of that shortcut (allowing hidden/dotted files and other
exact paths to bypass the *pattern* excludes) while still honouring
directory-level exclusions for those same files.
@codspeed-hq

codspeed-hq Bot commented Jun 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing LeSingh1:fix/file-filter-exclude-dirs-before-endswith (98f80fb) with main (e8a31bc)

Open in CodSpeed

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

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.

1 participant