From 3890bbe6f7f4261b29434feabd2c95c61f571eca Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 23 Jul 2020 17:05:59 +0200 Subject: [PATCH] vendor: update tonistiigi/fsutil v0.0.0-20200720184806-8f851f9d2045 full diff: https://github.com/tonistiigi/fsutil/compare/ae3a8d753069...8f851f9d2045 notable changes: - walker: fix notadir error - improving error returns - more typed errors - remove extra verbosity (eg. PathError already contains action and path) - ensure stack traces are added to errors Signed-off-by: Sebastiaan van Stijn --- go.mod | 2 +- go.sum | 4 ++-- vendor/github.com/tonistiigi/fsutil/.gitignore | 9 +++++++++ .../tonistiigi/fsutil/chtimes_nolinux.go | 6 ++++-- vendor/github.com/tonistiigi/fsutil/diff.go | 4 ++-- .../github.com/tonistiigi/fsutil/diskwriter.go | 9 +++++---- .../tonistiigi/fsutil/diskwriter_unix.go | 8 ++++---- .../tonistiigi/fsutil/followlinks.go | 10 +++++----- vendor/github.com/tonistiigi/fsutil/fs.go | 14 ++++++++------ .../github.com/tonistiigi/fsutil/hardlinks.go | 3 ++- vendor/github.com/tonistiigi/fsutil/send.go | 3 ++- vendor/github.com/tonistiigi/fsutil/stat.go | 6 +++--- .../github.com/tonistiigi/fsutil/tarwriter.go | 12 ++++++++---- .../github.com/tonistiigi/fsutil/validator.go | 7 ++++--- vendor/github.com/tonistiigi/fsutil/walker.go | 18 ++++++++---------- vendor/modules.txt | 2 +- 16 files changed, 68 insertions(+), 49 deletions(-) create mode 100644 vendor/github.com/tonistiigi/fsutil/.gitignore diff --git a/go.mod b/go.mod index a23838f7..23c5e6f7 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,7 @@ require ( github.com/sirupsen/logrus v1.4.2 github.com/stretchr/testify v1.5.1 github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 // indirect - github.com/tonistiigi/fsutil v0.0.0-20200512175118-ae3a8d753069 + github.com/tonistiigi/fsutil v0.0.0-20200720184806-8f851f9d2045 github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea github.com/uber/jaeger-client-go v2.11.2+incompatible github.com/uber/jaeger-lib v1.2.1 // indirect diff --git a/go.sum b/go.sum index 876d0775..56dcb329 100644 --- a/go.sum +++ b/go.sum @@ -213,8 +213,8 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 h1:b6uOv7YOFK0TYG7HtkIgExQo+2RdLuwRft63jn2HWj8= github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= -github.com/tonistiigi/fsutil v0.0.0-20200512175118-ae3a8d753069 h1:F8MYILe5YNjbPLpmF/OgYrfsHBnAFZecylt1AXl8zow= -github.com/tonistiigi/fsutil v0.0.0-20200512175118-ae3a8d753069/go.mod h1:uA7OEv9Ab41e89xMMPlecftcyNsXGVHuI71vi1acNeg= +github.com/tonistiigi/fsutil v0.0.0-20200720184806-8f851f9d2045 h1:aARPR+qSaJk8cf3pi09cdUxWF1UJ/3xFaZRwRewzdic= +github.com/tonistiigi/fsutil v0.0.0-20200720184806-8f851f9d2045/go.mod h1:uA7OEv9Ab41e89xMMPlecftcyNsXGVHuI71vi1acNeg= github.com/tonistiigi/go-immutable-radix v0.0.0-20170803185627-826af9ccf0fe h1:pd7hrFSqUPxYS9IB+UMG1AB/8EXGXo17ssx0bSQ5L6Y= github.com/tonistiigi/go-immutable-radix v0.0.0-20170803185627-826af9ccf0fe/go.mod h1:/+MCh11CJf2oz0BXmlmqyopK/ad1rKkcOXPoYuPCJYU= github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea h1:SXhTLE6pb6eld/v/cCndK0AMpt1wiVFb/YYmqB3/QG0= diff --git a/vendor/github.com/tonistiigi/fsutil/.gitignore b/vendor/github.com/tonistiigi/fsutil/.gitignore new file mode 100644 index 00000000..51b9602c --- /dev/null +++ b/vendor/github.com/tonistiigi/fsutil/.gitignore @@ -0,0 +1,9 @@ +# 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 +# support running go modules in vendor mode for local development +vendor/ diff --git a/vendor/github.com/tonistiigi/fsutil/chtimes_nolinux.go b/vendor/github.com/tonistiigi/fsutil/chtimes_nolinux.go index cdd80ec9..a3ba0988 100644 --- a/vendor/github.com/tonistiigi/fsutil/chtimes_nolinux.go +++ b/vendor/github.com/tonistiigi/fsutil/chtimes_nolinux.go @@ -5,16 +5,18 @@ package fsutil import ( "os" "time" + + "github.com/pkg/errors" ) func chtimes(path string, un int64) error { mtime := time.Unix(0, un) fi, err := os.Lstat(path) if err != nil { - return err + return errors.WithStack(err) } if fi.Mode()&os.ModeSymlink != 0 { return nil } - return os.Chtimes(path, mtime, mtime) + return errors.WithStack(os.Chtimes(path, mtime, mtime)) } diff --git a/vendor/github.com/tonistiigi/fsutil/diff.go b/vendor/github.com/tonistiigi/fsutil/diff.go index 1cbc32b3..135794e4 100644 --- a/vendor/github.com/tonistiigi/fsutil/diff.go +++ b/vendor/github.com/tonistiigi/fsutil/diff.go @@ -21,7 +21,7 @@ type ContentHasher func(*types.Stat) (hash.Hash, error) func GetWalkerFn(root string) walkerFn { return func(ctx context.Context, pathC chan<- *currentPath) error { - return Walk(ctx, root, nil, func(path string, f os.FileInfo, err error) error { + return errors.Wrap(Walk(ctx, root, nil, func(path string, f os.FileInfo, err error) error { if err != nil { return err } @@ -42,7 +42,7 @@ func GetWalkerFn(root string) walkerFn { case pathC <- p: return nil } - }) + }), "failed to walk") } } diff --git a/vendor/github.com/tonistiigi/fsutil/diskwriter.go b/vendor/github.com/tonistiigi/fsutil/diskwriter.go index 70323c88..7208adc6 100644 --- a/vendor/github.com/tonistiigi/fsutil/diskwriter.go +++ b/vendor/github.com/tonistiigi/fsutil/diskwriter.go @@ -8,6 +8,7 @@ import ( "path/filepath" "strconv" "sync" + "syscall" "time" "github.com/opencontainers/go-digest" @@ -104,7 +105,7 @@ func (dw *DiskWriter) HandleChange(kind ChangeKind, p string, fi os.FileInfo, er stat, ok := fi.Sys().(*types.Stat) if !ok { - return errors.Errorf("%s invalid change without stat information", p) + return errors.WithStack(&os.PathError{Path: p, Err: syscall.EBADMSG, Op: "change without stat info"}) } statCopy := *stat @@ -118,13 +119,13 @@ func (dw *DiskWriter) HandleChange(kind ChangeKind, p string, fi os.FileInfo, er rename := true oldFi, err := os.Lstat(destPath) if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { if kind != ChangeKindAdd { - return errors.Wrapf(err, "invalid addition: %s", destPath) + return errors.Wrap(err, "modify/rm") } rename = false } else { - return errors.Wrapf(err, "failed to stat %s", destPath) + return errors.WithStack(err) } } diff --git a/vendor/github.com/tonistiigi/fsutil/diskwriter_unix.go b/vendor/github.com/tonistiigi/fsutil/diskwriter_unix.go index ff0a22e3..aa2d298f 100644 --- a/vendor/github.com/tonistiigi/fsutil/diskwriter_unix.go +++ b/vendor/github.com/tonistiigi/fsutil/diskwriter_unix.go @@ -17,17 +17,17 @@ func rewriteMetadata(p string, stat *types.Stat) error { } if err := os.Lchown(p, int(stat.Uid), int(stat.Gid)); err != nil { - return errors.Wrapf(err, "failed to lchown %s", p) + return errors.WithStack(err) } if os.FileMode(stat.Mode)&os.ModeSymlink == 0 { if err := os.Chmod(p, os.FileMode(stat.Mode)); err != nil { - return errors.Wrapf(err, "failed to chown %s", p) + return errors.WithStack(err) } } if err := chtimes(p, stat.ModTime); err != nil { - return errors.Wrapf(err, "failed to chtimes %s", p) + return err } return nil @@ -46,7 +46,7 @@ func handleTarTypeBlockCharFifo(path string, stat *types.Stat) error { } if err := syscall.Mknod(path, mode, int(mkdev(stat.Devmajor, stat.Devminor))); err != nil { - return err + return errors.WithStack(err) } return nil } diff --git a/vendor/github.com/tonistiigi/fsutil/followlinks.go b/vendor/github.com/tonistiigi/fsutil/followlinks.go index ed4af6e8..a0942413 100644 --- a/vendor/github.com/tonistiigi/fsutil/followlinks.go +++ b/vendor/github.com/tonistiigi/fsutil/followlinks.go @@ -77,10 +77,10 @@ func (r *symlinkResolver) readSymlink(p string, allowWildcard bool) ([]string, e if allowWildcard && containsWildcards(base) { fis, err := ioutil.ReadDir(filepath.Dir(realPath)) if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { return nil, nil } - return nil, errors.Wrapf(err, "failed to read dir %s", filepath.Dir(realPath)) + return nil, errors.Wrap(err, "readdir") } var out []string for _, f := range fis { @@ -97,17 +97,17 @@ func (r *symlinkResolver) readSymlink(p string, allowWildcard bool) ([]string, e fi, err := os.Lstat(realPath) if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { return nil, nil } - return nil, errors.Wrapf(err, "failed to lstat %s", realPath) + return nil, errors.WithStack(err) } if fi.Mode()&os.ModeSymlink == 0 { return nil, nil } link, err := os.Readlink(realPath) if err != nil { - return nil, errors.Wrapf(err, "failed to readlink %s", realPath) + return nil, errors.WithStack(err) } link = filepath.Clean(link) if filepath.IsAbs(link) { diff --git a/vendor/github.com/tonistiigi/fsutil/fs.go b/vendor/github.com/tonistiigi/fsutil/fs.go index a9467e94..e26110b3 100644 --- a/vendor/github.com/tonistiigi/fsutil/fs.go +++ b/vendor/github.com/tonistiigi/fsutil/fs.go @@ -9,6 +9,7 @@ import ( "path/filepath" "sort" "strings" + "syscall" "github.com/pkg/errors" "github.com/tonistiigi/fsutil/types" @@ -36,7 +37,8 @@ func (fs *fs) Walk(ctx context.Context, fn filepath.WalkFunc) error { } func (fs *fs) Open(p string) (io.ReadCloser, error) { - return os.Open(filepath.Join(fs.root, p)) + rc, err := os.Open(filepath.Join(fs.root, p)) + return rc, errors.WithStack(err) } type Dir struct { @@ -51,10 +53,10 @@ func SubDirFS(dirs []Dir) (FS, error) { m := map[string]Dir{} for _, d := range dirs { if path.Base(d.Stat.Path) != d.Stat.Path { - return nil, errors.Errorf("subdir %s must be single file", d.Stat.Path) + return nil, errors.WithStack(&os.PathError{Path: d.Stat.Path, Err: syscall.EISDIR, Op: "invalid path"}) } if _, ok := m[d.Stat.Path]; ok { - return nil, errors.Errorf("invalid path %s", d.Stat.Path) + return nil, errors.WithStack(&os.PathError{Path: d.Stat.Path, Err: syscall.EEXIST, Op: "duplicate path"}) } m[d.Stat.Path] = d } @@ -70,7 +72,7 @@ func (fs *subDirFS) Walk(ctx context.Context, fn filepath.WalkFunc) error { for _, d := range fs.dirs { fi := &StatInfo{Stat: &d.Stat} if !fi.IsDir() { - return errors.Errorf("fs subdir %s not mode directory", d.Stat.Path) + return errors.WithStack(&os.PathError{Path: d.Stat.Path, Err: syscall.ENOTDIR, Op: "walk subdir"}) } if err := fn(d.Stat.Path, fi, nil); err != nil { return err @@ -78,7 +80,7 @@ func (fs *subDirFS) Walk(ctx context.Context, fn filepath.WalkFunc) error { if err := d.FS.Walk(ctx, func(p string, fi os.FileInfo, err error) error { stat, ok := fi.Sys().(*types.Stat) if !ok { - return errors.Wrapf(err, "invalid fileinfo without stat info: %s", p) + return errors.WithStack(&os.PathError{Path: d.Stat.Path, Err: syscall.EBADMSG, Op: "fileinfo without stat info"}) } stat.Path = path.Join(d.Stat.Path, stat.Path) if stat.Linkname != "" { @@ -105,7 +107,7 @@ func (fs *subDirFS) Open(p string) (io.ReadCloser, error) { } d, ok := fs.m[parts[0]] if !ok { - return nil, os.ErrNotExist + return nil, errors.WithStack(&os.PathError{Path: parts[0], Err: syscall.ENOENT, Op: "open"}) } return d.FS.Open(parts[1]) } diff --git a/vendor/github.com/tonistiigi/fsutil/hardlinks.go b/vendor/github.com/tonistiigi/fsutil/hardlinks.go index d977f0d6..ef8bbfb5 100644 --- a/vendor/github.com/tonistiigi/fsutil/hardlinks.go +++ b/vendor/github.com/tonistiigi/fsutil/hardlinks.go @@ -2,6 +2,7 @@ package fsutil import ( "os" + "syscall" "github.com/pkg/errors" "github.com/tonistiigi/fsutil/types" @@ -28,7 +29,7 @@ func (v *Hardlinks) HandleChange(kind ChangeKind, p string, fi os.FileInfo, err stat, ok := fi.Sys().(*types.Stat) if !ok { - return errors.Errorf("invalid change without stat info: %s", p) + return errors.WithStack(&os.PathError{Path: p, Err: syscall.EBADMSG, Op: "change without stat info"}) } if fi.IsDir() || fi.Mode()&os.ModeSymlink != 0 { diff --git a/vendor/github.com/tonistiigi/fsutil/send.go b/vendor/github.com/tonistiigi/fsutil/send.go index e7c5a37d..cee1aec5 100644 --- a/vendor/github.com/tonistiigi/fsutil/send.go +++ b/vendor/github.com/tonistiigi/fsutil/send.go @@ -5,6 +5,7 @@ import ( "io" "os" "sync" + "syscall" "github.com/pkg/errors" "github.com/tonistiigi/fsutil/types" @@ -148,7 +149,7 @@ func (s *sender) walk(ctx context.Context) error { } stat, ok := fi.Sys().(*types.Stat) if !ok { - return errors.Wrapf(err, "invalid fileinfo without stat info: %s", path) + return errors.WithStack(&os.PathError{Path: path, Err: syscall.EBADMSG, Op: "fileinfo without stat info"}) } p := &types.Packet{ diff --git a/vendor/github.com/tonistiigi/fsutil/stat.go b/vendor/github.com/tonistiigi/fsutil/stat.go index 789dce3d..2ab8da11 100644 --- a/vendor/github.com/tonistiigi/fsutil/stat.go +++ b/vendor/github.com/tonistiigi/fsutil/stat.go @@ -31,13 +31,13 @@ func mkstat(path, relpath string, fi os.FileInfo, inodemap map[uint64]string) (* if fi.Mode()&os.ModeSymlink != 0 { link, err := os.Readlink(path) if err != nil { - return nil, errors.Wrapf(err, "failed to readlink %s", path) + return nil, errors.WithStack(err) } stat.Linkname = link } } if err := loadXattr(path, stat); err != nil { - return nil, errors.Wrapf(err, "failed to xattr %s", relpath) + return nil, err } if runtime.GOOS == "windows" { @@ -58,7 +58,7 @@ func mkstat(path, relpath string, fi os.FileInfo, inodemap map[uint64]string) (* func Stat(path string) (*types.Stat, error) { fi, err := os.Lstat(path) if err != nil { - return nil, errors.Wrap(err, "os stat") + return nil, errors.WithStack(err) } return mkstat(path, filepath.Base(path), fi, nil) } diff --git a/vendor/github.com/tonistiigi/fsutil/tarwriter.go b/vendor/github.com/tonistiigi/fsutil/tarwriter.go index 06f28c55..ae7df831 100644 --- a/vendor/github.com/tonistiigi/fsutil/tarwriter.go +++ b/vendor/github.com/tonistiigi/fsutil/tarwriter.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "strings" + "syscall" "github.com/pkg/errors" "github.com/tonistiigi/fsutil/types" @@ -15,9 +16,12 @@ import ( func WriteTar(ctx context.Context, fs FS, w io.Writer) error { tw := tar.NewWriter(w) err := fs.Walk(ctx, func(path string, fi os.FileInfo, err error) error { + if err != nil && !errors.Is(err, os.ErrNotExist) { + return err + } stat, ok := fi.Sys().(*types.Stat) if !ok { - return errors.Wrapf(err, "invalid fileinfo without stat info: %s", path) + return errors.WithStack(&os.PathError{Path: path, Err: syscall.EBADMSG, Op: "fileinfo without stat info"}) } hdr, err := tar.FileInfoHeader(fi, stat.Linkname) if err != nil { @@ -52,7 +56,7 @@ func WriteTar(ctx context.Context, fs FS, w io.Writer) error { } if err := tw.WriteHeader(hdr); err != nil { - return errors.Wrap(err, "failed to write file header") + return errors.Wrapf(err, "failed to write file header %s", name) } if hdr.Typeflag == tar.TypeReg && hdr.Size > 0 && hdr.Linkname == "" { @@ -61,10 +65,10 @@ func WriteTar(ctx context.Context, fs FS, w io.Writer) error { return err } if _, err := io.Copy(tw, rc); err != nil { - return err + return errors.WithStack(err) } if err := rc.Close(); err != nil { - return err + return errors.WithStack(err) } } return nil diff --git a/vendor/github.com/tonistiigi/fsutil/validator.go b/vendor/github.com/tonistiigi/fsutil/validator.go index 2bd1287a..9bd7d94d 100644 --- a/vendor/github.com/tonistiigi/fsutil/validator.go +++ b/vendor/github.com/tonistiigi/fsutil/validator.go @@ -6,6 +6,7 @@ import ( "runtime" "sort" "strings" + "syscall" "github.com/pkg/errors" ) @@ -31,10 +32,10 @@ func (v *Validator) HandleChange(kind ChangeKind, p string, fi os.FileInfo, err p = strings.Replace(p, "\\", "", -1) } if p != path.Clean(p) { - return errors.Errorf("invalid unclean path %s", p) + return errors.WithStack(&os.PathError{Path: p, Err: syscall.EINVAL, Op: "unclean path"}) } if path.IsAbs(p) { - return errors.Errorf("abolute path %s not allowed", p) + return errors.WithStack(&os.PathError{Path: p, Err: syscall.EINVAL, Op: "absolute path"}) } dir := path.Dir(p) base := path.Base(p) @@ -42,7 +43,7 @@ func (v *Validator) HandleChange(kind ChangeKind, p string, fi os.FileInfo, err dir = "" } if dir == ".." || strings.HasPrefix(p, "../") { - return errors.Errorf("invalid path: %s", p) + return errors.WithStack(&os.PathError{Path: p, Err: syscall.EINVAL, Op: "escape check"}) } // find a parent dir from saved records diff --git a/vendor/github.com/tonistiigi/fsutil/walker.go b/vendor/github.com/tonistiigi/fsutil/walker.go index 6004b888..b10383e4 100644 --- a/vendor/github.com/tonistiigi/fsutil/walker.go +++ b/vendor/github.com/tonistiigi/fsutil/walker.go @@ -25,21 +25,21 @@ type WalkOpt struct { func Walk(ctx context.Context, p string, opt *WalkOpt, fn filepath.WalkFunc) error { root, err := filepath.EvalSymlinks(p) if err != nil { - return errors.Wrapf(err, "failed to resolve %s", root) + return errors.WithStack(&os.PathError{Op: "resolve", Path: root, Err: err}) } fi, err := os.Stat(root) if err != nil { - return errors.Wrapf(err, "failed to stat: %s", root) + return errors.WithStack(err) } if !fi.IsDir() { - return errors.Errorf("%s is not a directory", root) + return errors.WithStack(&os.PathError{Op: "walk", Path: root, Err: syscall.ENOTDIR}) } var pm *fileutils.PatternMatcher if opt != nil && opt.ExcludePatterns != nil { pm, err = fileutils.NewPatternMatcher(opt.ExcludePatterns) if err != nil { - return errors.Wrapf(err, "invalid excludepaths %s", opt.ExcludePatterns) + return errors.Wrapf(err, "invalid excludepatterns: %s", opt.ExcludePatterns) } } @@ -65,17 +65,15 @@ func Walk(ctx context.Context, p string, opt *WalkOpt, fn filepath.WalkFunc) err seenFiles := make(map[uint64]string) return filepath.Walk(root, func(path string, fi os.FileInfo, err error) (retErr error) { - if err != nil { - if os.IsNotExist(err) { - return filepath.SkipDir - } - return err - } defer func() { if retErr != nil && isNotExist(retErr) { retErr = filepath.SkipDir } }() + if err != nil { + return err + } + origpath := path path, err = filepath.Rel(root, path) if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 21a52bd7..8a288fa3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -297,7 +297,7 @@ github.com/stretchr/testify/assert github.com/stretchr/testify/require # github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 github.com/syndtr/gocapability/capability -# github.com/tonistiigi/fsutil v0.0.0-20200512175118-ae3a8d753069 +# github.com/tonistiigi/fsutil v0.0.0-20200720184806-8f851f9d2045 github.com/tonistiigi/fsutil github.com/tonistiigi/fsutil/copy github.com/tonistiigi/fsutil/types