Skip to content

Commit fee0995

Browse files
committed
Support patterns starting with ** in ignore files
Fixes: podman-container-tools/buildah#6417 Signed-off-by: Šimon Brauner <sbrauner@redhat.com>
1 parent 498ccd1 commit fee0995

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

storage/pkg/fileutils/fileutils.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ func (p *Pattern) Exclusion() bool {
181181
}
182182

183183
func (p *Pattern) match(path string) (bool, error) {
184+
if p.doubleAsteriskPrefixMatch(path) {
185+
return true, nil
186+
}
187+
184188
if p.regexp == nil {
185189
if err := p.compile(); err != nil {
186190
return false, filepath.ErrBadPattern
@@ -192,6 +196,21 @@ func (p *Pattern) match(path string) (bool, error) {
192196
return b, nil
193197
}
194198

199+
// https://github.com/podman-container-tools/buildah/issues/6417
200+
func (p *Pattern) doubleAsteriskPrefixMatch(path string) bool {
201+
pattern := p.cleanedPattern
202+
if !strings.HasPrefix(pattern, "**") || len(pattern) <= 2 || pattern[2] == os.PathSeparator {
203+
return false
204+
}
205+
206+
suffix := pattern[2:]
207+
if strings.ContainsAny(suffix, "*?[]") {
208+
return false
209+
}
210+
211+
return strings.HasSuffix(path, suffix)
212+
}
213+
195214
func (p *Pattern) compile() error {
196215
var regStrBuilder strings.Builder
197216
regStrBuilder.WriteString("^")

storage/pkg/fileutils/fileutils_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ func TestMatches(t *testing.T) {
356356
{"abc/**", "abc/def/ghi", false, true},
357357
{"**/.foo", ".foo", false, true},
358358
{"**/.foo", "bar.foo", false, false},
359+
{"**.md", "README.md", false, true},
360+
{"**.md", "foo/README.md", false, true},
359361
}
360362

361363
if runtime.GOOS != windows {

0 commit comments

Comments
 (0)