Merge pull request #848 from harshavardhana/pr_out_add_fakereader_to_sessions_to_populate_progress_bar_as_it_builds_and_skips_previously_uploaded_files
This commit is contained in:
@@ -79,14 +79,14 @@ func doCopySession(cURLs cpURLs, bar *barSend, s *sessionV1) error {
|
||||
|
||||
_, ok := s.Files[cURLs.SourceContent.Name]
|
||||
if ok {
|
||||
bar.ErrorGet(int64(cURLs.SourceContent.Size))
|
||||
putFakeTarget(bar.NewProxyReader(&fakeReader{size: cURLs.SourceContent.Size}))
|
||||
return nil
|
||||
}
|
||||
|
||||
reader, length, err := getSource(cURLs.SourceContent.Name)
|
||||
if err != nil {
|
||||
if !globalQuietFlag {
|
||||
bar.ErrorGet(int64(length))
|
||||
bar.ErrorGet(length)
|
||||
}
|
||||
return iodine.New(err, map[string]string{"URL": cURLs.SourceContent.Name})
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func doCopySession(cURLs cpURLs, bar *barSend, s *sessionV1) error {
|
||||
err = putTarget(cURLs.TargetContent.Name, length, newReader)
|
||||
if err != nil {
|
||||
if !globalQuietFlag {
|
||||
bar.ErrorPut(int64(length))
|
||||
bar.ErrorPut(length)
|
||||
}
|
||||
return iodine.New(err, map[string]string{"URL": cURLs.TargetContent.Name})
|
||||
}
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ func doSyncSession(sURLs syncURLs, bar *barSend, syncQueue chan bool, ssCh chan
|
||||
_, ok := s.Files[sURLs.SourceContent.Name]
|
||||
if ok {
|
||||
if !globalQuietFlag {
|
||||
bar.ErrorGet(int64(sURLs.SourceContent.Size))
|
||||
putFakeTarget(bar.NewProxyReader(&fakeReader{size: sURLs.SourceContent.Size}))
|
||||
}
|
||||
<-syncQueue // Signal that this copy routine is done.
|
||||
return
|
||||
|
||||
@@ -18,6 +18,7 @@ package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
@@ -38,6 +39,18 @@ const (
|
||||
pbBarCmdSetCaption
|
||||
)
|
||||
|
||||
type fakeReader struct {
|
||||
size int64
|
||||
}
|
||||
|
||||
func (r *fakeReader) Read(p []byte) (n int, err error) {
|
||||
return int(r.size), io.EOF
|
||||
}
|
||||
|
||||
func putFakeTarget(reader io.Reader) {
|
||||
io.Copy(ioutil.Discard, reader)
|
||||
}
|
||||
|
||||
type proxyReader struct {
|
||||
io.Reader
|
||||
bar *barSend
|
||||
@@ -49,6 +62,10 @@ func (r *proxyReader) Read(p []byte) (n int, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (b *barSend) NewProxyReader(r io.Reader) *proxyReader {
|
||||
return &proxyReader{r, b}
|
||||
}
|
||||
|
||||
type barMsg struct {
|
||||
Cmd pbBarCmd
|
||||
Arg interface{}
|
||||
@@ -75,10 +92,6 @@ func (b barSend) ErrorGet(size int64) {
|
||||
b.cmdCh <- barMsg{Cmd: pbBarCmdGetError, Arg: size}
|
||||
}
|
||||
|
||||
func (b *barSend) NewProxyReader(r io.Reader) *proxyReader {
|
||||
return &proxyReader{r, b}
|
||||
}
|
||||
|
||||
func (b *barSend) SetCaption(c string) {
|
||||
b.cmdCh <- barMsg{Cmd: pbBarCmdSetCaption, Arg: c}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user