(suffix string)
| 61 | } |
| 62 | |
| 63 | func (p *cliRestoreProgress) output(suffix string) { |
| 64 | if !p.enableProgress { |
| 65 | return |
| 66 | } |
| 67 | |
| 68 | // ensure the counters are not going back in an output line compared to the previous one |
| 69 | p.outputMutex.Lock() |
| 70 | defer p.outputMutex.Unlock() |
| 71 | |
| 72 | restoredCount := p.restoredCount.Load() |
| 73 | enqueuedCount := p.enqueuedCount.Load() |
| 74 | skippedCount := p.skippedCount.Load() |
| 75 | ignoredCount := p.ignoredErrorsCount.Load() |
| 76 | |
| 77 | restoredSize := p.restoredTotalFileSize.Load() |
| 78 | enqueuedSize := p.enqueuedTotalFileSize.Load() |
| 79 | skippedSize := p.skippedTotalFileSize.Load() |
| 80 | |
| 81 | if restoredSize == 0 { |
| 82 | return |
| 83 | } |
| 84 | |
| 85 | var maybeRemaining, maybeSkipped, maybeErrors string |
| 86 | if est, ok := p.eta.Estimate(float64(restoredSize), float64(enqueuedSize)); ok { |
| 87 | maybeRemaining = fmt.Sprintf(" %v (%.1f%%) remaining %v", |
| 88 | units.BytesPerSecondsString(est.SpeedPerSecond), |
| 89 | est.PercentComplete, |
| 90 | est.Remaining) |
| 91 | } |
| 92 | |
| 93 | if skippedCount > 0 { |
| 94 | maybeSkipped = fmt.Sprintf(", skipped %v (%v)", skippedCount, units.BytesString(skippedSize)) |
| 95 | } |
| 96 | |
| 97 | if ignoredCount > 0 { |
| 98 | maybeErrors = fmt.Sprintf(", ignored %v errors", ignoredCount) |
| 99 | } |
| 100 | |
| 101 | line := fmt.Sprintf("Processed %v (%v) of %v (%v)%v%v%v.", |
| 102 | restoredCount+skippedCount, units.BytesString(restoredSize), |
| 103 | enqueuedCount, units.BytesString(enqueuedSize), |
| 104 | maybeSkipped, maybeErrors, maybeRemaining, |
| 105 | ) |
| 106 | |
| 107 | var extraSpaces string |
| 108 | |
| 109 | if len(line) < p.lastLineLength { |
| 110 | // add extra spaces to wipe over previous line if it was longer than current |
| 111 | extraSpaces = strings.Repeat(" ", p.lastLineLength-len(line)) |
| 112 | } |
| 113 | |
| 114 | p.lastLineLength = len(line) |
| 115 | p.out.printStderr("\r%v%v%v", line, extraSpaces, suffix) |
| 116 | } |
no test coverage detected