fileutils: fix wildcard negation directory descent in archive.TarWithOptions#1006
Open
Honny1 wants to merge 1 commit into
Open
fileutils: fix wildcard negation directory descent in archive.TarWithOptions#1006Honny1 wants to merge 1 commit into
archive.TarWithOptions#1006Honny1 wants to merge 1 commit into
Conversation
Honny1
marked this pull request as ready for review
July 21, 2026 15:25
Honny1
force-pushed
the
fix-archive-filtering
branch
from
July 21, 2026 15:28
c1bc58d to
785ad11
Compare
…hOptions` The `strings.HasPrefix` check in `tarWithOptionsTo` only worked for literal negation patterns (e.g. `!cmd/main.go`) but failed for wildcard negations like `!**/*.go`, `!*/*.go`, or `!cmd/image*`. This caused excluded directories to be skipped entirely even when negation patterns should have re-included files within them. Add `ShouldDescendExcludedDir` to `pkg/fileutils` which extracts the literal prefix before the first wildcard character and checks whether the directory is at or under that prefix. When no literal prefix exists (e.g. `!**/*.go`), always descend. Replace the inline loop in tarWithOptionsTo with a call to the new function. Signed-off-by: Jan Rodák <hony.com@seznam.cz>
Honny1
force-pushed
the
fix-archive-filtering
branch
from
July 21, 2026 15:43
785ad11 to
2e515ea
Compare
mtrmac
reviewed
Jul 22, 2026
| // overmatch (descend into directories that won't ultimately contain matches), | ||
| // which is safe because actual file-level matching happens later. | ||
| func ShouldDescendExcludedDir(dirPath string, pm *PatternMatcher) bool { | ||
| if pm == nil || !pm.Exclusions() { |
Contributor
There was a problem hiding this comment.
Non-blocking: Do we need the pm == nil here? I think this is a caller error and not silently accepting it might make it easier to discover such errors.
| // the literal prefix before the first wildcard and may intentionally | ||
| // overmatch (descend into directories that won't ultimately contain matches), | ||
| // which is safe because actual file-level matching happens later. | ||
| func ShouldDescendExcludedDir(dirPath string, pm *PatternMatcher) bool { |
Contributor
There was a problem hiding this comment.
Did you consider making this a method of PatternMatcher? Any reason not to do that?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
strings.HasPrefixcheck intarWithOptionsToonly worked for literal negation patterns (e.g.!cmd/main.go) but failed for wildcard negations like!**/*.go,!*/*.go, or!cmd/image*. This caused excluded directories to be skipped entirely even when negation patterns should have re-included files within them.Add
ShouldDescendExcludedDirtopkg/fileutilswhich extracts the literal prefix before the first wildcard character and checks whether the directory is at or under that prefix. When no literal prefix exists (e.g.!**/*.go), always descend. Replace the inline loop in tarWithOptionsTo with a call to the new function.