diff --git a/go.mod b/go.mod index ecf5fd8e8cbe..ae50f7ca3bfa 100644 --- a/go.mod +++ b/go.mod @@ -68,7 +68,7 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/spdx/tools-golang v0.5.1 github.com/stretchr/testify v1.8.4 - github.com/tonistiigi/fsutil v0.0.0-20230825212630-f09800878302 + github.com/tonistiigi/fsutil v0.0.0-20240223190444-7a889f53dbf6 github.com/tonistiigi/go-actions-cache v0.0.0-20220404170428-0bdeb6e1eac7 github.com/tonistiigi/go-archvariant v1.0.0 github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea diff --git a/go.sum b/go.sum index 34569e781aae..77e50ab150f7 100644 --- a/go.sum +++ b/go.sum @@ -1212,8 +1212,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1 github.com/tommy-muehle/go-mnd v1.1.1/go.mod h1:dSUh0FtTP8VhvkL1S+gUR1OKd9ZnSaozuI6r3m6wOig= github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa/go.mod h1:dSUh0FtTP8VhvkL1S+gUR1OKd9ZnSaozuI6r3m6wOig= github.com/tonistiigi/fsutil v0.0.0-20201103201449-0834f99b7b85/go.mod h1:a7cilN64dG941IOXfhJhlH0qB92hxJ9A1ewrdUmJ6xo= -github.com/tonistiigi/fsutil v0.0.0-20230825212630-f09800878302 h1:ZT8ibgassurSISJ1Pj26NsM3vY2jxFZn63Nd/TpHmRw= -github.com/tonistiigi/fsutil v0.0.0-20230825212630-f09800878302/go.mod h1:9kMVqMyQ/Sx2df5LtnGG+nbrmiZzCS7V6gjW3oGHsvI= +github.com/tonistiigi/fsutil v0.0.0-20240223190444-7a889f53dbf6 h1:v9u6pmdUkarXL/1S/6LGcG9wsiBLd9N/WyJq/Y9WPcg= +github.com/tonistiigi/fsutil v0.0.0-20240223190444-7a889f53dbf6/go.mod h1:vbbYqJlnswsbJqWUcJN8fKtBhnEgldDrcagTgnBVKKM= github.com/tonistiigi/go-actions-cache v0.0.0-20220404170428-0bdeb6e1eac7 h1:8eY6m1mjgyB8XySUR7WvebTM8D/Vs86jLJzD/Tw7zkc= github.com/tonistiigi/go-actions-cache v0.0.0-20220404170428-0bdeb6e1eac7/go.mod h1:qqvyZqkfwkoJuPU/bw61bItaoO0SJ8YSW0vSVRRvsRg= github.com/tonistiigi/go-archvariant v1.0.0 h1:5LC1eDWiBNflnTF1prCiX09yfNHIxDC/aukdhCdTyb0= diff --git a/vendor/github.com/tonistiigi/fsutil/.gitignore b/vendor/github.com/tonistiigi/fsutil/.gitignore index 51b9602c84a3..e5c343e2d7ba 100644 --- a/vendor/github.com/tonistiigi/fsutil/.gitignore +++ b/vendor/github.com/tonistiigi/fsutil/.gitignore @@ -1,9 +1,5 @@ # if you want to ignore files created by your editor/tools, consider using a # global .gitignore or .git/info/exclude see https://help.github.com/articles/ignoring-files -.* -!.github -!.gitignore -!.travis.yml -*.prof +bin/ # support running go modules in vendor mode for local development vendor/ diff --git a/vendor/github.com/tonistiigi/fsutil/.golangci.yml b/vendor/github.com/tonistiigi/fsutil/.golangci.yml new file mode 100644 index 000000000000..7300a0e58268 --- /dev/null +++ b/vendor/github.com/tonistiigi/fsutil/.golangci.yml @@ -0,0 +1,30 @@ +run: + timeout: 10m + skip-files: + - ".*\\.pb\\.go$" + +linters: + enable: + - gofmt + - govet + - goimports + - ineffassign + - misspell + - unused + - staticcheck + - typecheck + disable-all: true + +linters-settings: + depguard: + rules: + main: + deny: + # The io/ioutil package has been deprecated. + # https://go.dev/doc/go1.16#ioutil + - pkg: "io/ioutil" + desc: The io/ioutil package has been deprecated. + +# show all +max-issues-per-linter: 0 +max-same-issues: 0 diff --git a/vendor/github.com/tonistiigi/fsutil/Dockerfile b/vendor/github.com/tonistiigi/fsutil/Dockerfile index 9584648d0583..21c1f39f6082 100644 --- a/vendor/github.com/tonistiigi/fsutil/Dockerfile +++ b/vendor/github.com/tonistiigi/fsutil/Dockerfile @@ -1,7 +1,9 @@ -#syntax=docker/dockerfile:1 -ARG GO_VERSION=1.20 +# syntax=docker/dockerfile:1 -FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.1.0 AS xx +ARG GO_VERSION=1.21 +ARG XX_VERSION=1.4.0 + +FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base RUN apk add --no-cache git @@ -18,13 +20,19 @@ FROM base AS test ARG TESTFLAGS RUN --mount=target=. --mount=target=/go/pkg/mod,type=cache \ --mount=target=/root/.cache,type=cache \ - CGO_ENABLED=0 xx-go test -test.v ${TESTFLAGS} ./... + CGO_ENABLED=0 xx-go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic ${TESTFLAGS} ./... FROM base AS test-noroot RUN mkdir /go/pkg && chmod 0777 /go/pkg USER 1000:1000 RUN --mount=target=. \ --mount=target=/tmp/.cache,type=cache \ - CGO_ENABLED=0 GOCACHE=/tmp/gocache xx-go test -test.v ./... + CGO_ENABLED=0 GOCACHE=/tmp/gocache xx-go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic ./... + +FROM scratch AS test-coverage +COPY --from=test /tmp/coverage.txt /coverage-root.txt + +FROM scratch AS test-noroot-coverage +COPY --from=test-noroot /tmp/coverage.txt /coverage-noroot.txt FROM build diff --git a/vendor/github.com/tonistiigi/fsutil/codecov.yml b/vendor/github.com/tonistiigi/fsutil/codecov.yml new file mode 100644 index 000000000000..f5f9e02cc887 --- /dev/null +++ b/vendor/github.com/tonistiigi/fsutil/codecov.yml @@ -0,0 +1,12 @@ +comment: false + +coverage: + status: + project: # settings affecting project coverage + default: + target: auto # auto % coverage target + threshold: 1% # allow for 1% reduction of coverage without failing + patch: off + +github_checks: + annotations: false diff --git a/vendor/github.com/tonistiigi/fsutil/copy/copy.go b/vendor/github.com/tonistiigi/fsutil/copy/copy.go index 558c553f7c5a..f8cc0a4331f7 100644 --- a/vendor/github.com/tonistiigi/fsutil/copy/copy.go +++ b/vendor/github.com/tonistiigi/fsutil/copy/copy.go @@ -88,7 +88,7 @@ func Copy(ctx context.Context, srcRoot, src, dstRoot, dst string, opts ...Opt) e return err } - c, err := newCopier(dstRoot, ci.Chown, ci.Utime, ci.Mode, ci.XAttrErrorHandler, ci.IncludePatterns, ci.ExcludePatterns, ci.ChangeFunc) + c, err := newCopier(dstRoot, ci.Chown, ci.Utime, ci.Mode, ci.XAttrErrorHandler, ci.IncludePatterns, ci.ExcludePatterns, ci.AlwaysReplaceExistingDestPaths, ci.ChangeFunc) if err != nil { return err } @@ -172,7 +172,11 @@ type CopyInfo struct { IncludePatterns []string // Exclude files/dir matching any of these patterns (even if they match an include pattern) ExcludePatterns []string - ChangeFunc fsutil.ChangeFunc + // If true, any source path that overwrite existing destination paths will always replace + // the existing destination path, even if they are of different types (e.g. a directory will + // replace any existing symlink or file) + AlwaysReplaceExistingDestPaths bool + ChangeFunc fsutil.ChangeFunc } type Opt func(*CopyInfo) @@ -227,16 +231,17 @@ func WithChangeNotifier(fn fsutil.ChangeFunc) Opt { } type copier struct { - chown Chowner - utime *time.Time - mode *int - inodes map[uint64]string - xattrErrorHandler XAttrErrorHandler - includePatternMatcher *patternmatcher.PatternMatcher - excludePatternMatcher *patternmatcher.PatternMatcher - parentDirs []parentDir - changefn fsutil.ChangeFunc - root string + chown Chowner + utime *time.Time + mode *int + inodes map[uint64]string + xattrErrorHandler XAttrErrorHandler + includePatternMatcher *patternmatcher.PatternMatcher + excludePatternMatcher *patternmatcher.PatternMatcher + parentDirs []parentDir + changefn fsutil.ChangeFunc + root string + alwaysReplaceExistingDestPaths bool } type parentDir struct { @@ -245,7 +250,7 @@ type parentDir struct { copied bool } -func newCopier(root string, chown Chowner, tm *time.Time, mode *int, xeh XAttrErrorHandler, includePatterns, excludePatterns []string, changeFunc fsutil.ChangeFunc) (*copier, error) { +func newCopier(root string, chown Chowner, tm *time.Time, mode *int, xeh XAttrErrorHandler, includePatterns, excludePatterns []string, alwaysReplaceExistingDestPaths bool, changeFunc fsutil.ChangeFunc) (*copier, error) { if xeh == nil { xeh = func(dst, src, key string, err error) error { return err @@ -271,15 +276,16 @@ func newCopier(root string, chown Chowner, tm *time.Time, mode *int, xeh XAttrEr } return &copier{ - root: root, - inodes: map[uint64]string{}, - chown: chown, - utime: tm, - xattrErrorHandler: xeh, - mode: mode, - includePatternMatcher: includePatternMatcher, - excludePatternMatcher: excludePatternMatcher, - changefn: changeFunc, + root: root, + inodes: map[uint64]string{}, + chown: chown, + utime: tm, + xattrErrorHandler: xeh, + mode: mode, + includePatternMatcher: includePatternMatcher, + excludePatternMatcher: excludePatternMatcher, + changefn: changeFunc, + alwaysReplaceExistingDestPaths: alwaysReplaceExistingDestPaths, }, nil } @@ -324,6 +330,10 @@ func (c *copier) copy(ctx context.Context, src, srcComponents, target string, ov } if include { + if err := c.removeTargetIfNeeded(src, target, fi, targetFi); err != nil { + return err + } + if err := c.createParentDirs(src, srcComponents, target, overwriteTargetMetadata); err != nil { return err } @@ -440,6 +450,21 @@ func (c *copier) exclude(path string, fi os.FileInfo, parentExcludeMatchInfo pat return m, matchInfo, nil } +func (c *copier) removeTargetIfNeeded(src, target string, srcFi, targetFi os.FileInfo) error { + if !c.alwaysReplaceExistingDestPaths { + return nil + } + if targetFi == nil { + // already doesn't exist + return nil + } + if srcFi.IsDir() && targetFi.IsDir() { + // directories are merged, not replaced + return nil + } + return os.RemoveAll(target) +} + // Delayed creation of parent directories when a file or dir matches an include // pattern. func (c *copier) createParentDirs(src, srcComponents, target string, overwriteTargetMetadata bool) error { diff --git a/vendor/github.com/tonistiigi/fsutil/copy/copy_darwin.go b/vendor/github.com/tonistiigi/fsutil/copy/copy_darwin.go index bc93b21cedaf..0cdc00a82cd9 100644 --- a/vendor/github.com/tonistiigi/fsutil/copy/copy_darwin.go +++ b/vendor/github.com/tonistiigi/fsutil/copy/copy_darwin.go @@ -13,7 +13,7 @@ import ( func copyFile(source, target string) error { if err := unix.Clonefileat(unix.AT_FDCWD, source, unix.AT_FDCWD, target, unix.CLONE_NOFOLLOW); err != nil { - if err != unix.EINVAL { + if err != unix.EINVAL && err != unix.EXDEV { return err } } else { diff --git a/vendor/github.com/tonistiigi/fsutil/copy/copy_linux.go b/vendor/github.com/tonistiigi/fsutil/copy/copy_linux.go index 971cb5c5d49c..6d9b490c66c0 100644 --- a/vendor/github.com/tonistiigi/fsutil/copy/copy_linux.go +++ b/vendor/github.com/tonistiigi/fsutil/copy/copy_linux.go @@ -30,7 +30,16 @@ func (c *copier) copyFileInfo(fi os.FileInfo, src, name string) error { m := fi.Mode() if c.mode != nil { - m = (m & ^os.FileMode(0777)) | os.FileMode(*c.mode&0777) + m = os.FileMode(*c.mode).Perm() + if *c.mode&syscall.S_ISGID != 0 { + m |= os.ModeSetgid + } + if *c.mode&syscall.S_ISUID != 0 { + m |= os.ModeSetuid + } + if *c.mode&syscall.S_ISVTX != 0 { + m |= os.ModeSticky + } } if (fi.Mode() & os.ModeSymlink) != os.ModeSymlink { if err := os.Chmod(name, m); err != nil { diff --git a/vendor/github.com/tonistiigi/fsutil/copy/copy_unix.go b/vendor/github.com/tonistiigi/fsutil/copy/copy_unix.go index 945e96c5f23d..4a7d0c86b1bb 100644 --- a/vendor/github.com/tonistiigi/fsutil/copy/copy_unix.go +++ b/vendor/github.com/tonistiigi/fsutil/copy/copy_unix.go @@ -31,7 +31,16 @@ func (c *copier) copyFileInfo(fi os.FileInfo, src, name string) error { m := fi.Mode() if c.mode != nil { - m = (m & ^os.FileMode(0777)) | os.FileMode(*c.mode&0777) + m = os.FileMode(*c.mode).Perm() + if *c.mode&syscall.S_ISGID != 0 { + m |= os.ModeSetgid + } + if *c.mode&syscall.S_ISUID != 0 { + m |= os.ModeSetuid + } + if *c.mode&syscall.S_ISVTX != 0 { + m |= os.ModeSticky + } } if (fi.Mode() & os.ModeSymlink) != os.ModeSymlink { if err := os.Chmod(name, m); err != nil { diff --git a/vendor/github.com/tonistiigi/fsutil/diff_containerd.go b/vendor/github.com/tonistiigi/fsutil/diff_containerd.go index d8619abf1c08..84fdc89dc5bf 100644 --- a/vendor/github.com/tonistiigi/fsutil/diff_containerd.go +++ b/vendor/github.com/tonistiigi/fsutil/diff_containerd.go @@ -5,6 +5,7 @@ import ( "context" "io" "os" + "path/filepath" "strings" "github.com/tonistiigi/fsutil/types" @@ -110,7 +111,7 @@ func doubleWalkDiff(ctx context.Context, changeFn ChangeFunc, a, b walkerFn, fil if filter != nil { filter(f2.path, &statCopy) } - f2copy = ¤tPath{path: f2.path, stat: &statCopy} + f2copy = ¤tPath{path: filepath.FromSlash(f2.path), stat: &statCopy} } k, p := pathChange(f1, f2copy) switch k { @@ -127,7 +128,7 @@ func doubleWalkDiff(ctx context.Context, changeFn ChangeFunc, a, b walkerFn, fil f1 = nil continue } else if rmdir == "" && f1.stat.IsDir() { - rmdir = f1.path + string(os.PathSeparator) + rmdir = f1.path + string(filepath.Separator) } else if rmdir != "" { rmdir = "" } @@ -138,7 +139,7 @@ func doubleWalkDiff(ctx context.Context, changeFn ChangeFunc, a, b walkerFn, fil return err } if f1.stat.IsDir() && !f2copy.stat.IsDir() { - rmdir = f1.path + string(os.PathSeparator) + rmdir = f1.path + string(filepath.Separator) } else if rmdir != "" { rmdir = "" } diff --git a/vendor/github.com/tonistiigi/fsutil/docker-bake.hcl b/vendor/github.com/tonistiigi/fsutil/docker-bake.hcl index 6ba3c867247c..48127d4ff0fc 100644 --- a/vendor/github.com/tonistiigi/fsutil/docker-bake.hcl +++ b/vendor/github.com/tonistiigi/fsutil/docker-bake.hcl @@ -1,5 +1,9 @@ variable "GO_VERSION" { - default = "1.20" + default = null +} + +variable "DESTDIR" { + default = "./bin" } group "default" { @@ -18,12 +22,14 @@ group "test" { target "test-root" { inherits = ["build"] - target = "test" + target = "test-coverage" + output = ["${DESTDIR}/coverage"] } target "test-noroot" { inherits = ["build"] - target = "test-noroot" + target = "test-noroot-coverage" + output = ["${DESTDIR}/coverage"] } target "lint" { diff --git a/vendor/github.com/tonistiigi/fsutil/filter.go b/vendor/github.com/tonistiigi/fsutil/filter.go index 05f4a466f9ff..9cee8ad238ac 100644 --- a/vendor/github.com/tonistiigi/fsutil/filter.go +++ b/vendor/github.com/tonistiigi/fsutil/filter.go @@ -66,9 +66,9 @@ type filterFS struct { // NewFilterFS creates a new FS that filters the given FS using the given // FilterOpt. - +// // The returned FS will not contain any paths that do not match the provided -// include and exclude patterns, or that are are exlcluded using the mapping +// include and exclude patterns, or that are are excluded using the mapping // function. // // The FS is assumed to be a snapshot of the filesystem at the time of the @@ -96,7 +96,7 @@ func NewFilterFS(fs FS, opt *FilterOpt) (FS, error) { } patternChars := "*[]?^" - if os.PathSeparator != '\\' { + if filepath.Separator != '\\' { patternChars += `\` } @@ -176,6 +176,7 @@ func (fs *filterFS) Walk(ctx context.Context, target string, fn gofs.WalkDirFunc includeMatchInfo patternmatcher.MatchInfo excludeMatchInfo patternmatcher.MatchInfo calledFn bool + skipFn bool } // used only for include/exclude handling @@ -333,6 +334,9 @@ func (fs *filterFS) Walk(ctx context.Context, target string, fn gofs.WalkDirFunc } } for i, parentDir := range parentDirs { + if parentDir.skipFn { + return filepath.SkipDir + } if parentDir.calledFn { continue } @@ -352,15 +356,21 @@ func (fs *filterFS) Walk(ctx context.Context, target string, fn gofs.WalkDirFunc } if fs.mapFn != nil { result := fs.mapFn(parentStat.Path, parentStat) - if result == MapResultSkipDir || result == MapResultExclude { + if result == MapResultExclude { continue + } else if result == MapResultSkipDir { + parentDirs[i].skipFn = true + return filepath.SkipDir } } - if err := fn(parentStat.Path, &DirEntryInfo{Stat: parentStat}, nil); err != nil { + parentDirs[i].calledFn = true + if err := fn(parentStat.Path, &DirEntryInfo{Stat: parentStat}, nil); err == filepath.SkipDir { + parentDirs[i].skipFn = true + return filepath.SkipDir + } else if err != nil { return err } - parentDirs[i].calledFn = true } if err := fn(stat.Path, &DirEntryInfo{Stat: stat}, nil); err != nil { return err diff --git a/vendor/github.com/tonistiigi/fsutil/followlinks.go b/vendor/github.com/tonistiigi/fsutil/followlinks.go index 3a0bd2bb790a..559291d79d9a 100644 --- a/vendor/github.com/tonistiigi/fsutil/followlinks.go +++ b/vendor/github.com/tonistiigi/fsutil/followlinks.go @@ -137,8 +137,8 @@ func (r *symlinkResolver) readSymlink(p string, allowWildcard bool) ([]string, e func statFile(fs FS, root string) (os.DirEntry, error) { var out os.DirEntry - root = filepath.Clean(root) - if root == "/" || root == "." { + root = filepath.FromSlash(filepath.Clean(root)) + if root == string(filepath.Separator) || root == "." { return nil, nil } @@ -168,8 +168,8 @@ func statFile(fs FS, root string) (os.DirEntry, error) { func readDir(fs FS, root string) ([]os.DirEntry, error) { var out []os.DirEntry - root = filepath.Clean(root) - if root == "/" || root == "." { + root = filepath.FromSlash(filepath.Clean(root)) + if root == string(filepath.Separator) || root == "." { root = "." out = make([]gofs.DirEntry, 0) } diff --git a/vendor/github.com/tonistiigi/fsutil/readme.md b/vendor/github.com/tonistiigi/fsutil/readme.md index 5ce685b7edc7..c417168876fa 100644 --- a/vendor/github.com/tonistiigi/fsutil/readme.md +++ b/vendor/github.com/tonistiigi/fsutil/readme.md @@ -1,3 +1,8 @@ +[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?style=flat-square&logo=go&logoColor=white)](https://pkg.go.dev/github.com/tonistiigi/fsutil) +[![CI Status](https://img.shields.io/github/actions/workflow/status/tonistiigi/fsutil/ci.yml?label=ci&logo=github&style=flat-square)](https://github.com/tonistiigi/fsutil/actions?query=workflow%3Aci) +[![Go Report Card](https://goreportcard.com/badge/github.com/tonistiigi/fsutil?style=flat-square)](https://goreportcard.com/report/github.com/tonistiigi/fsutil) +[![Codecov](https://img.shields.io/codecov/c/github/tonistiigi/fsutil?logo=codecov&style=flat-square)](https://codecov.io/gh/tonistiigi/fsutil) + Incremental file directory sync tools in golang. ``` diff --git a/vendor/github.com/tonistiigi/fsutil/send.go b/vendor/github.com/tonistiigi/fsutil/send.go index a044d04d8385..6a935ed06c03 100644 --- a/vendor/github.com/tonistiigi/fsutil/send.go +++ b/vendor/github.com/tonistiigi/fsutil/send.go @@ -4,6 +4,7 @@ import ( "context" "io" "os" + "path/filepath" "sync" "syscall" @@ -156,7 +157,7 @@ func (s *sender) walk(ctx context.Context) error { if !ok { return errors.WithStack(&os.PathError{Path: path, Err: syscall.EBADMSG, Op: "fileinfo without stat info"}) } - + stat.Path = filepath.ToSlash(stat.Path) p := &types.Packet{ Type: types.PACKET_STAT, Stat: stat, diff --git a/vendor/github.com/tonistiigi/fsutil/stat.go b/vendor/github.com/tonistiigi/fsutil/stat.go index 2ab8da118e2c..44441cb65696 100644 --- a/vendor/github.com/tonistiigi/fsutil/stat.go +++ b/vendor/github.com/tonistiigi/fsutil/stat.go @@ -19,7 +19,7 @@ func mkstat(path, relpath string, fi os.FileInfo, inodemap map[uint64]string) (* relpath = filepath.ToSlash(relpath) stat := &types.Stat{ - Path: relpath, + Path: filepath.FromSlash(relpath), Mode: uint32(fi.Mode()), ModTime: fi.ModTime().UnixNano(), } diff --git a/vendor/github.com/tonistiigi/fsutil/validator.go b/vendor/github.com/tonistiigi/fsutil/validator.go index 9bd7d94d3643..8b0dd91ec4df 100644 --- a/vendor/github.com/tonistiigi/fsutil/validator.go +++ b/vendor/github.com/tonistiigi/fsutil/validator.go @@ -2,8 +2,7 @@ package fsutil import ( "os" - "path" - "runtime" + "path/filepath" "sort" "strings" "syscall" @@ -28,21 +27,18 @@ func (v *Validator) HandleChange(kind ChangeKind, p string, fi os.FileInfo, err if v.parentDirs == nil { v.parentDirs = make([]parent, 1, 10) } - if runtime.GOOS == "windows" { - p = strings.Replace(p, "\\", "", -1) - } - if p != path.Clean(p) { + if p != filepath.Clean(p) { return errors.WithStack(&os.PathError{Path: p, Err: syscall.EINVAL, Op: "unclean path"}) } - if path.IsAbs(p) { + if filepath.IsAbs(p) { return errors.WithStack(&os.PathError{Path: p, Err: syscall.EINVAL, Op: "absolute path"}) } - dir := path.Dir(p) - base := path.Base(p) + dir := filepath.Dir(p) + base := filepath.Base(p) if dir == "." { dir = "" } - if dir == ".." || strings.HasPrefix(p, "../") { + if dir == ".." || strings.HasPrefix(p, filepath.FromSlash("../")) { return errors.WithStack(&os.PathError{Path: p, Err: syscall.EINVAL, Op: "escape check"}) } @@ -56,12 +52,12 @@ func (v *Validator) HandleChange(kind ChangeKind, p string, fi os.FileInfo, err } if dir != v.parentDirs[len(v.parentDirs)-1].dir || v.parentDirs[i].last >= base { - return errors.Errorf("changes out of order: %q %q", p, path.Join(v.parentDirs[i].dir, v.parentDirs[i].last)) + return errors.Errorf("changes out of order: %q %q", p, filepath.Join(v.parentDirs[i].dir, v.parentDirs[i].last)) } v.parentDirs[i].last = base if kind != ChangeKindDelete && fi.IsDir() { v.parentDirs = append(v.parentDirs, parent{ - dir: path.Join(dir, base), + dir: filepath.Join(dir, base), last: "", }) } @@ -76,7 +72,7 @@ func ComparePath(p1, p2 string) int { switch { case p1[i] == p2[i]: continue - case p2[i] != '/' && p1[i] < p2[i] || p1[i] == '/': + case p2[i] != filepath.Separator && p1[i] < p2[i] || p1[i] == filepath.Separator: return -1 default: return 1 diff --git a/vendor/modules.txt b/vendor/modules.txt index eaf290e59a69..4bb0a7d5abfd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -760,8 +760,8 @@ github.com/spdx/tools-golang/spdx/v2/v2_3 ## explicit; go 1.20 github.com/stretchr/testify/assert github.com/stretchr/testify/require -# github.com/tonistiigi/fsutil v0.0.0-20230825212630-f09800878302 -## explicit; go 1.19 +# github.com/tonistiigi/fsutil v0.0.0-20240223190444-7a889f53dbf6 +## explicit; go 1.20 github.com/tonistiigi/fsutil github.com/tonistiigi/fsutil/copy github.com/tonistiigi/fsutil/types