Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sync slow 2.9 #9168

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkg/skaffold/docker/dockerignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package docker
import (
"fmt"
"path/filepath"
"strings"

"github.com/moby/patternmatcher"

Expand All @@ -42,6 +43,32 @@ func NewDockerIgnorePredicate(workspace string, excludes []string) (walk.Predica
if err != nil {
return false, err
}

if ignored && info.IsDir() && skipDir(relPath, matcher) {
return false, filepath.SkipDir
}

return ignored, nil
}, nil
}

// exclusion handling closely follows vendor/github.com/docker/docker/pkg/archive/archive.go
func skipDir(relPath string, matcher *patternmatcher.PatternMatcher) bool {
// No exceptions (!...) in patterns so just skip dir
if !matcher.Exclusions() {
return true
}

dirSlash := relPath + string(filepath.Separator)

for _, pat := range matcher.Patterns() {
if !pat.Exclusion() {
continue
}
if strings.HasPrefix(pat.String()+string(filepath.Separator), dirSlash) {
// found a match - so can't skip this dir
return false
}
}
return true
}
Loading