From 0e8c5df478ccccf3d34748b8b9e53998dbac74e5 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 21 Sep 2017 18:22:14 -0700 Subject: [PATCH 1/2] vendor: update fsutil Signed-off-by: Tonis Tiigi --- session/filesync/diffcopy.go | 2 +- vendor.conf | 2 +- .../github.com/tonistiigi/fsutil/validator.go | 18 +++++++++++------- vendor/github.com/tonistiigi/fsutil/walker.go | 14 ++++++++++---- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/session/filesync/diffcopy.go b/session/filesync/diffcopy.go index 66d31e231377..87dd0a3296ed 100644 --- a/session/filesync/diffcopy.go +++ b/session/filesync/diffcopy.go @@ -12,7 +12,7 @@ import ( func sendDiffCopy(stream grpc.Stream, dir string, includes, excludes []string, progress progressCb) error { return fsutil.Send(stream.Context(), stream, dir, &fsutil.WalkOpt{ ExcludePatterns: excludes, - IncludePaths: includes, // TODO: rename IncludePatterns + IncludePatterns: includes, }, progress) } diff --git a/vendor.conf b/vendor.conf index 2aafba397666..f3760bd0f78e 100644 --- a/vendor.conf +++ b/vendor.conf @@ -36,7 +36,7 @@ github.com/BurntSushi/locker 392720b78f44e9d0249fcac6c43b111b47a370b8 github.com/docker/docker 6f723db8c6f0c7f0b252674a9673a25b5978db04 https://github.com/tonistiigi/docker.git github.com/pkg/profile 5b67d428864e92711fcbd2f8629456121a56d91f -github.com/tonistiigi/fsutil d49833a9a6fa5b41f63e7e338038633d10276b57 +github.com/tonistiigi/fsutil 1dedf6e90084bd88c4c518a15e68a37ed1370203 github.com/stevvooe/continuity 86cec1535a968310e7532819f699ff2830ed7463 github.com/dmcgowan/go-tar 2e2c51242e8993c50445dab7c03c8e7febddd0cf github.com/hashicorp/go-immutable-radix 826af9ccf0feeee615d546d69b11f8e98da8c8f1 git://github.com/tonistiigi/go-immutable-radix.git diff --git a/vendor/github.com/tonistiigi/fsutil/validator.go b/vendor/github.com/tonistiigi/fsutil/validator.go index e4a5eba66b08..2bd1287a8535 100644 --- a/vendor/github.com/tonistiigi/fsutil/validator.go +++ b/vendor/github.com/tonistiigi/fsutil/validator.go @@ -2,7 +2,8 @@ package fsutil import ( "os" - "path/filepath" + "path" + "runtime" "sort" "strings" @@ -26,14 +27,17 @@ func (v *Validator) HandleChange(kind ChangeKind, p string, fi os.FileInfo, err if v.parentDirs == nil { v.parentDirs = make([]parent, 1, 10) } - if p != filepath.Clean(p) { + if runtime.GOOS == "windows" { + p = strings.Replace(p, "\\", "", -1) + } + if p != path.Clean(p) { return errors.Errorf("invalid unclean path %s", p) } - if filepath.IsAbs(p) { + if path.IsAbs(p) { return errors.Errorf("abolute path %s not allowed", p) } - dir := filepath.Dir(p) - base := filepath.Base(p) + dir := path.Dir(p) + base := path.Base(p) if dir == "." { dir = "" } @@ -51,12 +55,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, filepath.Join(v.parentDirs[i].dir, v.parentDirs[i].last)) + return errors.Errorf("changes out of order: %q %q", p, path.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: filepath.Join(dir, base), + dir: path.Join(dir, base), last: "", }) } diff --git a/vendor/github.com/tonistiigi/fsutil/walker.go b/vendor/github.com/tonistiigi/fsutil/walker.go index bfec609b5a45..db1af56b49de 100644 --- a/vendor/github.com/tonistiigi/fsutil/walker.go +++ b/vendor/github.com/tonistiigi/fsutil/walker.go @@ -13,8 +13,9 @@ import ( ) type WalkOpt struct { - IncludePaths []string // todo: remove? + IncludePatterns []string ExcludePatterns []string + Map func(*Stat) bool } func Walk(ctx context.Context, p string, opt *WalkOpt, fn filepath.WalkFunc) error { @@ -57,9 +58,9 @@ func Walk(ctx context.Context, p string, opt *WalkOpt, fn filepath.WalkFunc) err } if opt != nil { - if opt.IncludePaths != nil { + if opt.IncludePatterns != nil { matched := false - for _, p := range opt.IncludePaths { + for _, p := range opt.IncludePatterns { if m, _ := filepath.Match(p, path); m { matched = true break @@ -138,7 +139,12 @@ func Walk(ctx context.Context, p string, opt *WalkOpt, fn filepath.WalkFunc) err case <-ctx.Done(): return ctx.Err() default: - if err := fn(path, &StatInfo{stat}, nil); err != nil { + if opt != nil && opt.Map != nil { + if allowed := opt.Map(stat); !allowed { + return nil + } + } + if err := fn(stat.Path, &StatInfo{stat}, nil); err != nil { return err } } From c2dbdeb457ea665699a5d97f79eebfac4ab4726f Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 21 Sep 2017 22:14:11 -0700 Subject: [PATCH 2/2] session: expose map to file send Signed-off-by: Tonis Tiigi --- session/filesync/diffcopy.go | 3 ++- session/filesync/filesync.go | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/session/filesync/diffcopy.go b/session/filesync/diffcopy.go index 87dd0a3296ed..c5a3b5bd6e65 100644 --- a/session/filesync/diffcopy.go +++ b/session/filesync/diffcopy.go @@ -9,10 +9,11 @@ import ( "google.golang.org/grpc" ) -func sendDiffCopy(stream grpc.Stream, dir string, includes, excludes []string, progress progressCb) error { +func sendDiffCopy(stream grpc.Stream, dir string, includes, excludes []string, progress progressCb, _map func(*fsutil.Stat) bool) error { return fsutil.Send(stream.Context(), stream, dir, &fsutil.WalkOpt{ ExcludePatterns: excludes, IncludePatterns: includes, + Map: _map, }, progress) } diff --git a/session/filesync/filesync.go b/session/filesync/filesync.go index 53bd4248d6fe..5642f07ac449 100644 --- a/session/filesync/filesync.go +++ b/session/filesync/filesync.go @@ -29,6 +29,7 @@ type SyncedDir struct { Name string Dir string Excludes []string + Map func(*fsutil.Stat) bool } // NewFSSyncProvider creates a new provider for sending files from client @@ -94,7 +95,7 @@ func (sp *fsSyncProvider) handle(method string, stream grpc.ServerStream) error doneCh = sp.doneCh sp.doneCh = nil } - err := pr.sendFn(stream, dir.Dir, includes, excludes, progress) + err := pr.sendFn(stream, dir.Dir, includes, excludes, progress, dir.Map) if doneCh != nil { if err != nil { doneCh <- err @@ -113,7 +114,7 @@ type progressCb func(int, bool) type protocol struct { name string - sendFn func(stream grpc.Stream, srcDir string, includes, excludes []string, progress progressCb) error + sendFn func(stream grpc.Stream, srcDir string, includes, excludes []string, progress progressCb, _map func(*fsutil.Stat) bool) error recvFn func(stream grpc.Stream, destDir string, cu CacheUpdater, progress progressCb) error } @@ -236,5 +237,5 @@ func CopyToCaller(ctx context.Context, srcPath string, c session.Caller, progres return err } - return sendDiffCopy(cc, srcPath, nil, nil, progress) + return sendDiffCopy(cc, srcPath, nil, nil, progress, nil) }