Merge pull request #126 from tonistiigi/update-fsutil

vendor: update fsutil
docker-18.09
Akihiro Suda 2017-09-23 01:19:55 +09:00 committed by GitHub
commit aaff9d591e
5 changed files with 29 additions and 17 deletions

View File

@ -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,
IncludePaths: includes, // TODO: rename IncludePatterns
IncludePatterns: includes,
Map: _map,
}, progress)
}

View File

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

View File

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

View File

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

View File

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