vendor: update fsutil to cb2ad947b
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>docker-18.09
parent
98f1604134
commit
5c3cfe5553
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/moby/buildkit/snapshot"
|
||||
"github.com/moby/buildkit/util/progress"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tonistiigi/fsutil"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
|
@ -82,7 +83,7 @@ func (e *localExporterInstance) Export(ctx context.Context, ref cache.ImmutableR
|
|||
}
|
||||
|
||||
progress := newProgressHandler(ctx, "copying files")
|
||||
if err := filesync.CopyToCaller(ctx, src, e.caller, progress); err != nil {
|
||||
if err := filesync.CopyToCaller(ctx, fsutil.NewFS(src, nil), e.caller, progress); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
|
|
|
@ -12,13 +12,8 @@ import (
|
|||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func sendDiffCopy(stream grpc.Stream, dir string, includes, excludes, followPaths []string, progress progressCb, _map func(*fsutil.Stat) bool) error {
|
||||
return fsutil.Send(stream.Context(), stream, dir, &fsutil.WalkOpt{
|
||||
ExcludePatterns: excludes,
|
||||
IncludePatterns: includes,
|
||||
FollowPaths: followPaths,
|
||||
Map: _map,
|
||||
}, progress)
|
||||
func sendDiffCopy(stream grpc.Stream, fs fsutil.FS, progress progressCb) error {
|
||||
return fsutil.Send(stream.Context(), stream, fs, progress)
|
||||
}
|
||||
|
||||
func newStreamWriter(stream grpc.ClientStream) io.WriteCloser {
|
||||
|
|
|
@ -101,7 +101,12 @@ func (sp *fsSyncProvider) handle(method string, stream grpc.ServerStream) (retEr
|
|||
doneCh = sp.doneCh
|
||||
sp.doneCh = nil
|
||||
}
|
||||
err := pr.sendFn(stream, dir.Dir, includes, excludes, followPaths, progress, dir.Map)
|
||||
err := pr.sendFn(stream, fsutil.NewFS(dir.Dir, &fsutil.WalkOpt{
|
||||
ExcludePatterns: excludes,
|
||||
IncludePatterns: includes,
|
||||
FollowPaths: followPaths,
|
||||
Map: dir.Map,
|
||||
}), progress)
|
||||
if doneCh != nil {
|
||||
if err != nil {
|
||||
doneCh <- err
|
||||
|
@ -120,7 +125,7 @@ type progressCb func(int, bool)
|
|||
|
||||
type protocol struct {
|
||||
name string
|
||||
sendFn func(stream grpc.Stream, srcDir string, includes, excludes, followPaths []string, progress progressCb, _map func(*fsutil.Stat) bool) error
|
||||
sendFn func(stream grpc.Stream, fs fsutil.FS, progress progressCb) error
|
||||
recvFn func(stream grpc.Stream, destDir string, cu CacheUpdater, progress progressCb) error
|
||||
}
|
||||
|
||||
|
@ -256,7 +261,7 @@ func (sp *fsSyncTarget) DiffCopy(stream FileSend_DiffCopyServer) error {
|
|||
return writeTargetFile(stream, sp.outfile)
|
||||
}
|
||||
|
||||
func CopyToCaller(ctx context.Context, srcPath string, c session.Caller, progress func(int, bool)) error {
|
||||
func CopyToCaller(ctx context.Context, fs fsutil.FS, c session.Caller, progress func(int, bool)) error {
|
||||
method := session.MethodURL(_FileSend_serviceDesc.ServiceName, "diffcopy")
|
||||
if !c.Supports(method) {
|
||||
return errors.Errorf("method %s not supported by the client", method)
|
||||
|
@ -269,7 +274,7 @@ func CopyToCaller(ctx context.Context, srcPath string, c session.Caller, progres
|
|||
return err
|
||||
}
|
||||
|
||||
return sendDiffCopy(cc, srcPath, nil, nil, nil, progress, nil)
|
||||
return sendDiffCopy(cc, fs, progress)
|
||||
}
|
||||
|
||||
func CopyFileWriter(ctx context.Context, c session.Caller) (io.WriteCloser, error) {
|
||||
|
|
|
@ -39,7 +39,7 @@ golang.org/x/time f51c12702a4d776e4c1fa9b0fabab841babae631
|
|||
github.com/docker/docker 71cd53e4a197b303c6ba086bd584ffd67a884281
|
||||
github.com/pkg/profile 5b67d428864e92711fcbd2f8629456121a56d91f
|
||||
|
||||
github.com/tonistiigi/fsutil 8abad97ee3969cdf5e9c367f46adba2c212b3ddb
|
||||
github.com/tonistiigi/fsutil cb2ad947b24dff140361a3aaaba18b32275f7c0c
|
||||
github.com/hashicorp/go-immutable-radix 826af9ccf0feeee615d546d69b11f8e98da8c8f1 git://github.com/tonistiigi/go-immutable-radix.git
|
||||
github.com/hashicorp/golang-lru a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4
|
||||
github.com/mitchellh/hashstructure 2bca23e0e452137f789efbc8610126fd8b94f73b
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package fsutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type FS interface {
|
||||
Walk(context.Context, filepath.WalkFunc) error
|
||||
Open(string) (io.ReadCloser, error)
|
||||
}
|
||||
|
||||
func NewFS(root string, opt *WalkOpt) FS {
|
||||
return &fs{
|
||||
root: root,
|
||||
opt: opt,
|
||||
}
|
||||
}
|
||||
|
||||
type fs struct {
|
||||
root string
|
||||
opt *WalkOpt
|
||||
}
|
||||
|
||||
func (fs *fs) Walk(ctx context.Context, fn filepath.WalkFunc) error {
|
||||
return Walk(ctx, fs.root, fs.opt, fn)
|
||||
}
|
||||
|
||||
func (fs *fs) Open(p string) (io.ReadCloser, error) {
|
||||
return os.Open(filepath.Join(fs.root, p))
|
||||
}
|
||||
|
||||
func SubDirFS(fs FS, stat Stat) FS {
|
||||
return &subDirFS{fs: fs, stat: stat}
|
||||
}
|
||||
|
||||
type subDirFS struct {
|
||||
fs FS
|
||||
stat Stat
|
||||
}
|
||||
|
||||
func (fs *subDirFS) Walk(ctx context.Context, fn filepath.WalkFunc) error {
|
||||
main := &StatInfo{Stat: &fs.stat}
|
||||
if !main.IsDir() {
|
||||
return errors.Errorf("fs subdir not mode directory")
|
||||
}
|
||||
if main.Name() != fs.stat.Path {
|
||||
return errors.Errorf("subdir path must be single file")
|
||||
}
|
||||
if err := fn(fs.stat.Path, main, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return fs.fs.Walk(ctx, func(p string, fi os.FileInfo, err error) error {
|
||||
stat, ok := fi.Sys().(*Stat)
|
||||
if !ok {
|
||||
return errors.Wrapf(err, "invalid fileinfo without stat info: %s", p)
|
||||
}
|
||||
stat.Path = path.Join(fs.stat.Path, stat.Path)
|
||||
return fn(filepath.Join(fs.stat.Path, p), &StatInfo{stat}, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func (fs *subDirFS) Open(p string) (io.ReadCloser, error) {
|
||||
return fs.fs.Open(strings.TrimPrefix(p, fs.stat.Path+"/"))
|
||||
}
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -23,11 +22,10 @@ type Stream interface {
|
|||
Context() context.Context
|
||||
}
|
||||
|
||||
func Send(ctx context.Context, conn Stream, root string, opt *WalkOpt, progressCb func(int, bool)) error {
|
||||
func Send(ctx context.Context, conn Stream, fs FS, progressCb func(int, bool)) error {
|
||||
s := &sender{
|
||||
conn: &syncStream{Stream: conn},
|
||||
root: root,
|
||||
opt: opt,
|
||||
fs: fs,
|
||||
files: make(map[uint32]string),
|
||||
progressCb: progressCb,
|
||||
sendpipeline: make(chan *sendHandle, 128),
|
||||
|
@ -42,8 +40,7 @@ type sendHandle struct {
|
|||
|
||||
type sender struct {
|
||||
conn Stream
|
||||
opt *WalkOpt
|
||||
root string
|
||||
fs FS
|
||||
files map[uint32]string
|
||||
mu sync.RWMutex
|
||||
progressCb func(int, bool)
|
||||
|
@ -130,7 +127,7 @@ func (s *sender) queue(id uint32) error {
|
|||
}
|
||||
|
||||
func (s *sender) sendFile(h *sendHandle) error {
|
||||
f, err := os.Open(filepath.Join(s.root, h.path))
|
||||
f, err := s.fs.Open(h.path)
|
||||
if err == nil {
|
||||
defer f.Close()
|
||||
buf := bufPool.Get().([]byte)
|
||||
|
@ -144,7 +141,7 @@ func (s *sender) sendFile(h *sendHandle) error {
|
|||
|
||||
func (s *sender) walk(ctx context.Context) error {
|
||||
var i uint32 = 0
|
||||
err := Walk(ctx, s.root, s.opt, func(path string, fi os.FileInfo, err error) error {
|
||||
err := s.fs.Walk(ctx, func(path string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue