Merge pull request #1589 from thaJeztah/update_fsutil

vendor: update tonistiigi/fsutil v0.0.0-20200720184806-8f851f9d2045
v0.8
Tõnis Tiigi 2020-07-23 09:25:57 -07:00 committed by GitHub
commit 754bcfbe51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 68 additions and 49 deletions

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

9
vendor/github.com/tonistiigi/fsutil/.gitignore generated vendored Normal file
View File

@ -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/

View File

@ -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))
}

View File

@ -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")
}
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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) {

View File

@ -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])
}

View File

@ -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 {

View File

@ -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{

View File

@ -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)
}

View File

@ -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

View File

@ -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

View File

@ -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 {

2
vendor/modules.txt vendored
View File

@ -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