From e880f5adee44471abaedf5ee8bd3a9ee56fbc6a3 Mon Sep 17 00:00:00 2001 From: ericzzzzzzz <102683393+ericzzzzzzz@users.noreply.github.com> Date: Wed, 8 Nov 2023 17:23:59 -0500 Subject: [PATCH] fix: sync slow (#9167) --- pkg/skaffold/docker/dockerignore.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/skaffold/docker/dockerignore.go b/pkg/skaffold/docker/dockerignore.go index 265a92d1e76..e99530c090c 100644 --- a/pkg/skaffold/docker/dockerignore.go +++ b/pkg/skaffold/docker/dockerignore.go @@ -19,6 +19,7 @@ package docker import ( "fmt" "path/filepath" + "strings" "github.com/moby/patternmatcher" @@ -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 +}