Skip to content

Commit

Permalink
fix: sync slow (#9168)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzzzzzzz authored Nov 9, 2023
1 parent 6071a3f commit 0dd8f00
Showing 1 changed file with 27 additions and 0 deletions.
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
}

0 comments on commit 0dd8f00

Please sign in to comment.