Delay progress output until the transfer starts

If progress is not delayed it can interfere with credential helpers
asking for credentials to make the API calls.
This commit is contained in:
rubyist 2015-07-31 10:30:08 -04:00
parent cc0bf4194b
commit 87fbb85def
2 changed files with 12 additions and 4 deletions

@ -22,6 +22,7 @@ type ProgressMeter struct {
estimatedBytes int64
currentBytes int64
skippedBytes int64
started int32
estimatedFiles int
startTime time.Time
finished chan interface{}
@ -38,7 +39,7 @@ func NewProgressMeter(estFiles int, estBytes int64, dryRun bool) *ProgressMeter
fmt.Fprintf(os.Stderr, "Error creating progress logger: %s\n", err)
}
pm := &ProgressMeter{
return &ProgressMeter{
logger: logger,
startTime: time.Now(),
fileIndex: make(map[string]int64),
@ -47,10 +48,12 @@ func NewProgressMeter(estFiles int, estBytes int64, dryRun bool) *ProgressMeter
estimatedBytes: estBytes,
dryRun: dryRun,
}
}
go pm.writer()
return pm
func (p *ProgressMeter) Start() {
if atomic.SwapInt32(&p.started, 1) == 0 {
go p.writer()
}
}
// Add tells the progress meter that a transferring file is being added to the

@ -106,6 +106,7 @@ func (q *TransferQueue) individualApiRoutine(apiWaiter chan interface{}) {
}
if apiWaiter != nil { // Signal to launch more individual api workers
q.meter.Start()
select {
case apiWaiter <- 1:
default:
@ -148,6 +149,8 @@ func (q *TransferQueue) legacyFallback(failedBatch []Transferable) {
// making only one POST call for all objects. The results are then handed
// off to the transfer workers.
func (q *TransferQueue) batchApiRoutine() {
var startProgress sync.Once
for {
batch := q.batcher.Next()
if batch == nil {
@ -174,6 +177,8 @@ func (q *TransferQueue) batchApiRoutine() {
continue
}
startProgress.Do(q.meter.Start)
for _, o := range objects {
if _, ok := o.Links[q.transferKind]; ok {
// This object needs to be transferred