2017-07-13 03:45:53 +00:00
|
|
|
package filesync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2017-07-19 01:05:19 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-07-13 03:45:53 +00:00
|
|
|
"github.com/tonistiigi/fsutil"
|
2017-07-11 17:12:12 +00:00
|
|
|
"google.golang.org/grpc"
|
2017-07-13 03:45:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}, progress)
|
|
|
|
}
|
|
|
|
|
2017-07-21 00:27:59 +00:00
|
|
|
func recvDiffCopy(ds grpc.Stream, dest string, cu CacheUpdater, progress progressCb) error {
|
2017-07-13 03:45:53 +00:00
|
|
|
st := time.Now()
|
|
|
|
defer func() {
|
|
|
|
logrus.Debugf("diffcopy took: %v", time.Since(st))
|
|
|
|
}()
|
|
|
|
var cf fsutil.ChangeFunc
|
2017-07-31 22:06:59 +00:00
|
|
|
var ch fsutil.ContentHasher
|
2017-07-13 03:45:53 +00:00
|
|
|
if cu != nil {
|
|
|
|
cu.MarkSupported(true)
|
|
|
|
cf = cu.HandleChange
|
2017-07-31 22:06:59 +00:00
|
|
|
ch = cu.ContentHasher()
|
2017-07-13 03:45:53 +00:00
|
|
|
}
|
2017-07-31 22:06:59 +00:00
|
|
|
return fsutil.Receive(ds.Context(), ds, dest, cf, ch, progress)
|
2017-07-13 03:45:53 +00:00
|
|
|
}
|