Skip to content

Fix WcMatch returning a file after a directory hook aborts - #252

Merged
facelessuser merged 1 commit into
facelessuser:mainfrom
spicysharkco:fix/directory-hook-abort
Oct 23, 2026
Merged

facelessuser merged 1 commit into
facelessuser:mainfrom
spicysharkco:fix/directory-hook-abort

Conversation

@spicysharkco

Copy link
Copy Markdown
Contributor

With root/a.txt, root/b.txt, and root/sub/c.txt, WcMatch('root', '*.txt', flags=RECURSIVE).match() returns:

  • on_validate_directory calls kill() and returns True: ['root/b.txt'].
  • on_validate_directory raises OSError; on_error calls kill(): ['root/b.txt'].

Both should return [], matching kill's documented "gracefully kill the internal searching" behavior.

_walk breaks only the directory loop, then searches files before checking the abort flag.

The abort flag is now checked before entering the file loop. Walks without kill() and calls to kill() while iterating imatch() keep their results (test_abort).

Both new tests fail without the fix and pass with it.

A directory validation hook can call kill directly or through its error
handler. Stop before searching files when either hook aborts the walk.
@gir-bot gir-bot added S: needs-review Needs to be reviewed and/or approved. C: docs Related to documentation. C: source Related to source code. C: tests Related to testing. C: wcmatch Wcmatch library. labels Oct 23, 2026
@facelessuser

Copy link
Copy Markdown
Owner

I'm not sure I'd call this a bug, per se. Aborts aren't guaranteed to stop immediately; it's more whenever it's done with what it is doing and gets to the next abort checkpoint, but an extra check before iterating files probably isn't bad.

@facelessuser

Copy link
Copy Markdown
Owner

@gir-bot lgtm

@gir-bot gir-bot added S: approved The pull request is ready to be merged. and removed S: needs-review Needs to be reviewed and/or approved. labels Oct 23, 2026
@facelessuser
facelessuser merged commit a987304 into facelessuser:main Oct 23, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C: docs Related to documentation. C: source Related to source code. C: tests Related to testing. C: wcmatch Wcmatch library. S: approved The pull request is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants