diff --git a/go.mod b/go.mod index f5ccde96..29e15857 100644 --- a/go.mod +++ b/go.mod @@ -58,7 +58,7 @@ require ( replace ( github.com/docker/cli => github.com/docker/cli v20.10.3-0.20210702143511-f782d1355eff+incompatible github.com/docker/docker => github.com/tonistiigi/docker v0.10.1-0.20211122204227-65a6f25dbca2 - github.com/tonistiigi/fsutil => github.com/tonistiigi/fsutil v0.0.0-20211122210416-da5201e0b3af + github.com/tonistiigi/fsutil => github.com/tonistiigi/fsutil v0.0.0-20211222194517-22a581344001 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.0.0-20210714055410-d010b05b4939 go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace => github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/net/http/httptrace/otelhttptrace v0.0.0-20210714055410-d010b05b4939 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp => github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/net/http/otelhttp v0.0.0-20210714055410-d010b05b4939 diff --git a/go.sum b/go.sum index 226fb4bb..c21db230 100644 --- a/go.sum +++ b/go.sum @@ -1201,8 +1201,8 @@ github.com/tommy-muehle/go-mnd v1.1.1/go.mod h1:dSUh0FtTP8VhvkL1S+gUR1OKd9ZnSaoz github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa/go.mod h1:dSUh0FtTP8VhvkL1S+gUR1OKd9ZnSaozuI6r3m6wOig= github.com/tonistiigi/docker v0.10.1-0.20211122204227-65a6f25dbca2 h1:e6PyP4Gi3HZ9hSH9gGGGSaBh3EI+HZj5E4fgEV43ZCI= github.com/tonistiigi/docker v0.10.1-0.20211122204227-65a6f25dbca2/go.mod h1:v9W/4hjeg+54O4ffkt1Dnh7nOIE9uHi9F0W9clN3nTQ= -github.com/tonistiigi/fsutil v0.0.0-20211122210416-da5201e0b3af h1:G5OoRy5gm3D9uLT0JIlgjB0aJPyTM48GFDqS9ESQPW4= -github.com/tonistiigi/fsutil v0.0.0-20211122210416-da5201e0b3af/go.mod h1:WnebnONB1EcTV5BdGlPLPlCX+FVMKhTnGZP2BvmyhgE= +github.com/tonistiigi/fsutil v0.0.0-20211222194517-22a581344001 h1:Xa39RCQdfLqzbqRFvJ80w+a4OaLSdTiNk9AlQHuB5A8= +github.com/tonistiigi/fsutil v0.0.0-20211222194517-22a581344001/go.mod h1:lJAxK//iyZ3yGbQswdrPTxugZIDM7sd4bEsD0x3XMHk= github.com/tonistiigi/go-actions-cache v0.0.0-20211002214948-4d48f2ff622a/go.mod h1:YiIBjH5gP7mao3t0dBrNNBGuKYdeJmcAJjYLXr43k6A= github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.0.0-20210714055410-d010b05b4939 h1:s6wDMZYNyWt8KvkjhrMpOthFPgI3JB8ipJS+eCV/psg= github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.0.0-20210714055410-d010b05b4939/go.mod h1:Vm5u/mtkj1OMhtao0v+BGo2LUoLCgHYXvRmj0jWITlE= diff --git a/vendor/github.com/tonistiigi/fsutil/go.mod b/vendor/github.com/tonistiigi/fsutil/go.mod index e302be14..fc4cdb00 100644 --- a/vendor/github.com/tonistiigi/fsutil/go.mod +++ b/vendor/github.com/tonistiigi/fsutil/go.mod @@ -4,7 +4,7 @@ go 1.13 require ( github.com/containerd/continuity v0.1.0 - github.com/docker/docker v20.10.3-0.20210817025855-ba2adeebdb8d+incompatible // master (v21.xx-dev) + github.com/docker/docker v20.10.3-0.20210609071616-4c2ec79bf2a8+incompatible // master (v21.xx-dev) github.com/gogo/protobuf v1.3.2 github.com/golang/protobuf v1.4.3 // indirect github.com/google/go-cmp v0.5.2 // indirect @@ -18,5 +18,3 @@ require ( gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gotest.tools/v3 v3.0.3 // indirect ) - -replace github.com/docker/docker => github.com/aaronlehmann/docker v1.4.2-0.20211119215941-554d44fa45a2 diff --git a/vendor/github.com/tonistiigi/fsutil/go.sum b/vendor/github.com/tonistiigi/fsutil/go.sum index 679ac870..a16eb8fe 100644 --- a/vendor/github.com/tonistiigi/fsutil/go.sum +++ b/vendor/github.com/tonistiigi/fsutil/go.sum @@ -2,8 +2,6 @@ bazil.org/fuse v0.0.0-20160811212531-371fbbdaa898/go.mod h1:Xbm+BRKSBEpa4q4hTSxo cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/aaronlehmann/docker v1.4.2-0.20211119215941-554d44fa45a2 h1:W1DM5Z2Yym6DVr1Qcx+HCECYYjoAGWfYfgS1prcqoc4= -github.com/aaronlehmann/docker v1.4.2-0.20211119215941-554d44fa45a2/go.mod h1:fLQH6hJxU6jTc+JFQWNyw/nl0i9+jjwDmugekrLew18= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= @@ -25,6 +23,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/docker/docker v20.10.3-0.20210609071616-4c2ec79bf2a8+incompatible h1:vDUpBEVNJURujPYAl6dHaG0UDLJ7vl7m8/ZZOjAP3gg= +github.com/docker/docker v20.10.3-0.20210609071616-4c2ec79bf2a8+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= diff --git a/vendor/github.com/tonistiigi/fsutil/prefix/match.go b/vendor/github.com/tonistiigi/fsutil/prefix/match.go new file mode 100644 index 00000000..57e745c6 --- /dev/null +++ b/vendor/github.com/tonistiigi/fsutil/prefix/match.go @@ -0,0 +1,45 @@ +package prefix + +import ( + "path" + "path/filepath" + "strings" +) + +// Match matches a path against a pattern. It returns m = true if the path +// matches the pattern, and partial = true if the pattern has more separators +// than the path and the common components match (for example, name = foo and +// pattern = foo/bar/*). slashSeparator determines whether the path and pattern +// are '/' delimited (true) or use the native path separator (false). +func Match(pattern, name string, slashSeparator bool) (m bool, partial bool) { + separator := filepath.Separator + if slashSeparator { + separator = '/' + } + count := strings.Count(name, string(separator)) + if strings.Count(pattern, string(separator)) > count { + pattern = trimUntilIndex(pattern, string(separator), count) + partial = true + } + if slashSeparator { + m, _ = path.Match(pattern, name) + } else { + m, _ = filepath.Match(pattern, name) + } + return m, partial +} + +func trimUntilIndex(str, sep string, count int) string { + s := str + i := 0 + c := 0 + for { + idx := strings.Index(s, sep) + s = s[idx+len(sep):] + i += idx + len(sep) + c++ + if c > count { + return str[:i-len(sep)] + } + } +} diff --git a/vendor/github.com/tonistiigi/fsutil/walker.go b/vendor/github.com/tonistiigi/fsutil/walker.go index b41d1bd5..cc6143db 100644 --- a/vendor/github.com/tonistiigi/fsutil/walker.go +++ b/vendor/github.com/tonistiigi/fsutil/walker.go @@ -10,6 +10,7 @@ import ( "github.com/docker/docker/pkg/fileutils" "github.com/pkg/errors" + "github.com/tonistiigi/fsutil/prefix" "github.com/tonistiigi/fsutil/types" ) @@ -35,15 +36,20 @@ func Walk(ctx context.Context, p string, opt *WalkOpt, fn filepath.WalkFunc) err return errors.WithStack(&os.PathError{Op: "walk", Path: root, Err: syscall.ENOTDIR}) } - var ( - includePatterns []string - includeMatcher *fileutils.PatternMatcher - excludeMatcher *fileutils.PatternMatcher - ) + var pm *fileutils.PatternMatcher + if opt != nil && opt.ExcludePatterns != nil { + pm, err = fileutils.NewPatternMatcher(opt.ExcludePatterns) + if err != nil { + return errors.Wrapf(err, "invalid excludepatterns: %s", opt.ExcludePatterns) + } + } + var includePatterns []string if opt != nil && opt.IncludePatterns != nil { includePatterns = make([]string, len(opt.IncludePatterns)) - copy(includePatterns, opt.IncludePatterns) + for k := range opt.IncludePatterns { + includePatterns[k] = filepath.Clean(opt.IncludePatterns[k]) + } } if opt != nil && opt.FollowPaths != nil { targets, err := FollowLinks(p, opt.FollowPaths) @@ -55,32 +61,8 @@ func Walk(ctx context.Context, p string, opt *WalkOpt, fn filepath.WalkFunc) err includePatterns = dedupePaths(includePatterns) } } - if len(includePatterns) != 0 { - includeMatcher, err = fileutils.NewPatternMatcher(includePatterns) - if err != nil { - return errors.Wrapf(err, "invalid includepatterns: %s", opt.IncludePatterns) - } - } - - if opt != nil && opt.ExcludePatterns != nil { - excludeMatcher, err = fileutils.NewPatternMatcher(opt.ExcludePatterns) - if err != nil { - return errors.Wrapf(err, "invalid excludepatterns: %s", opt.ExcludePatterns) - } - } - type visitedDir struct { - fi os.FileInfo - path string - origpath string - pathWithSep string - includeMatchInfo fileutils.MatchInfo - excludeMatchInfo fileutils.MatchInfo - calledFn bool - } - - // used only for include/exclude handling - var parentDirs []visitedDir + var lastIncludedDir string seenFiles := make(map[uint64]string) return filepath.Walk(root, func(path string, fi os.FileInfo, err error) (retErr error) { @@ -103,84 +85,67 @@ func Walk(ctx context.Context, p string, opt *WalkOpt, fn filepath.WalkFunc) err return nil } - var dir visitedDir - - if includeMatcher != nil || excludeMatcher != nil { - for len(parentDirs) != 0 { - lastParentDir := parentDirs[len(parentDirs)-1].pathWithSep - if strings.HasPrefix(path, lastParentDir) { - break + if opt != nil { + if includePatterns != nil { + skip := false + if lastIncludedDir != "" { + if strings.HasPrefix(path, lastIncludedDir+string(filepath.Separator)) { + skip = true + } } - parentDirs = parentDirs[:len(parentDirs)-1] - } - if fi.IsDir() { - dir = visitedDir{ - fi: fi, - path: path, - origpath: origpath, - pathWithSep: path + string(filepath.Separator), + if !skip { + matched := false + partial := true + for _, pattern := range includePatterns { + if ok, p := prefix.Match(pattern, path, false); ok { + matched = true + if !p { + partial = false + break + } + } + } + if !matched { + if fi.IsDir() { + return filepath.SkipDir + } + return nil + } + if !partial && fi.IsDir() { + lastIncludedDir = path + } } } - } - - skip := false - - if includeMatcher != nil { - var parentIncludeMatchInfo fileutils.MatchInfo - if len(parentDirs) != 0 { - parentIncludeMatchInfo = parentDirs[len(parentDirs)-1].includeMatchInfo - } - m, matchInfo, err := includeMatcher.MatchesUsingParentResults(path, parentIncludeMatchInfo) - if err != nil { - return errors.Wrap(err, "failed to match includepatterns") - } - - if fi.IsDir() { - dir.includeMatchInfo = matchInfo - } - - if !m { - skip = true - } - } - - if excludeMatcher != nil { - var parentExcludeMatchInfo fileutils.MatchInfo - if len(parentDirs) != 0 { - parentExcludeMatchInfo = parentDirs[len(parentDirs)-1].excludeMatchInfo - } - m, matchInfo, err := excludeMatcher.MatchesUsingParentResults(path, parentExcludeMatchInfo) - if err != nil { - return errors.Wrap(err, "failed to match excludepatterns") - } - - if fi.IsDir() { - dir.excludeMatchInfo = matchInfo - } - - if m { - if fi.IsDir() && !excludeMatcher.Exclusions() { - return filepath.SkipDir + if pm != nil { + m, err := pm.Matches(path) + if err != nil { + return errors.Wrap(err, "failed to match excludepatterns") } - skip = true - } - } - if includeMatcher != nil || excludeMatcher != nil { - defer func() { - if fi.IsDir() { - parentDirs = append(parentDirs, dir) + if m { + if fi.IsDir() { + if !pm.Exclusions() { + return filepath.SkipDir + } + dirSlash := path + string(filepath.Separator) + for _, pat := range pm.Patterns() { + if !pat.Exclusion() { + continue + } + patStr := pat.String() + string(filepath.Separator) + if strings.HasPrefix(patStr, dirSlash) { + goto passedFilter + } + } + return filepath.SkipDir + } + return nil } - }() - } - - if skip { - return nil + } } - dir.calledFn = true - + passedFilter: stat, err := mkstat(origpath, path, fi, seenFiles) if err != nil { return err @@ -195,31 +160,6 @@ func Walk(ctx context.Context, p string, opt *WalkOpt, fn filepath.WalkFunc) err return nil } } - for i, parentDir := range parentDirs { - if parentDir.calledFn { - continue - } - parentStat, err := mkstat(parentDir.origpath, parentDir.path, parentDir.fi, seenFiles) - if err != nil { - return err - } - - select { - case <-ctx.Done(): - return ctx.Err() - default: - } - if opt != nil && opt.Map != nil { - if allowed := opt.Map(parentStat.Path, parentStat); !allowed { - continue - } - } - - if err := fn(parentStat.Path, &StatInfo{parentStat}, nil); err != nil { - return err - } - parentDirs[i].calledFn = true - } if err := fn(stat.Path, &StatInfo{stat}, nil); err != nil { return err } diff --git a/vendor/modules.txt b/vendor/modules.txt index a5eb2cb3..1878b67d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -416,8 +416,9 @@ github.com/theupdateframework/notary/tuf/data github.com/theupdateframework/notary/tuf/signed github.com/theupdateframework/notary/tuf/utils github.com/theupdateframework/notary/tuf/validation -# github.com/tonistiigi/fsutil v0.0.0-20210818161904-4442383b5028 => github.com/tonistiigi/fsutil v0.0.0-20211122210416-da5201e0b3af +# github.com/tonistiigi/fsutil v0.0.0-20210818161904-4442383b5028 => github.com/tonistiigi/fsutil v0.0.0-20211222194517-22a581344001 github.com/tonistiigi/fsutil +github.com/tonistiigi/fsutil/prefix github.com/tonistiigi/fsutil/types # github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea ## explicit @@ -872,7 +873,7 @@ sigs.k8s.io/structured-merge-diff/v4/value sigs.k8s.io/yaml # github.com/docker/cli => github.com/docker/cli v20.10.3-0.20210702143511-f782d1355eff+incompatible # github.com/docker/docker => github.com/tonistiigi/docker v0.10.1-0.20211122204227-65a6f25dbca2 -# github.com/tonistiigi/fsutil => github.com/tonistiigi/fsutil v0.0.0-20211122210416-da5201e0b3af +# github.com/tonistiigi/fsutil => github.com/tonistiigi/fsutil v0.0.0-20211222194517-22a581344001 # go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.0.0-20210714055410-d010b05b4939 # go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace => github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/net/http/httptrace/otelhttptrace v0.0.0-20210714055410-d010b05b4939 # go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp => github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/net/http/otelhttp v0.0.0-20210714055410-d010b05b4939