diff --git a/utils/progressbar/progressbarmng.go b/utils/progressbar/progressbarmng.go index d9e7ff010..2c9dce525 100644 --- a/utils/progressbar/progressbarmng.go +++ b/utils/progressbar/progressbarmng.go @@ -95,18 +95,17 @@ func (bm *ProgressBarMng) newDoubleValueProgressBar(getVal func() (firstNumerato if err != nil { log.Error(err) } - numeratorString := artifactoryutils.ConvertIntToStorageSizeString(getProgressNumerator(statistics, *firstNumerator, *firstDenominator)) - denominatorString := artifactoryutils.ConvertIntToStorageSizeString(*firstDenominator) - return color.Green.Render(numeratorString + "/" + denominatorString) - }), - decor.Name(" "+secondValueLine+": "), decor.Any(func(statistics decor.Statistics) string { + s1 := artifactoryutils.ConvertIntToStorageSizeString(*firstNumerator) + s2 := artifactoryutils.ConvertIntToStorageSizeString(*firstDenominator) + return color.Green.Render(s1 + "/" + s2) + }), decor.Name(" "+secondValueLine+": "), decor.Any(func(statistics decor.Statistics) string { _, _, secondNumerator, secondDenominator, err := getVal() if err != nil { log.Error(err) } - numeratorString := strconv.FormatInt(getProgressNumerator(statistics, *secondNumerator, *secondDenominator), 10) - denominatorString := strconv.Itoa(int(*secondDenominator)) - return color.Green.Render(numeratorString + "/" + denominatorString) + s1 := strconv.Itoa(int(*secondNumerator)) + s2 := strconv.Itoa(int(*secondDenominator)) + return color.Green.Render(s1 + "/" + s2) }), ), ) @@ -189,9 +188,7 @@ func (bm *ProgressBarMng) NewHeadlineBar(msg string) *mpb.Bar { func (bm *ProgressBarMng) Increment(prog *TasksWithHeadlineProg) { bm.barsRWMutex.RLock() defer bm.barsRWMutex.RUnlock() - if prog.tasksProgressBar.bar.Current() < math.MaxInt64 { - prog.tasksProgressBar.bar.Increment() - } + prog.tasksProgressBar.bar.Increment() prog.tasksProgressBar.tasksCount++ } @@ -199,9 +196,7 @@ func (bm *ProgressBarMng) Increment(prog *TasksWithHeadlineProg) { func (bm *ProgressBarMng) IncBy(n int, prog *TasksWithHeadlineProg) { bm.barsRWMutex.RLock() defer bm.barsRWMutex.RUnlock() - if prog.tasksProgressBar.bar.Current() < math.MaxInt64 { - prog.tasksProgressBar.bar.IncrBy(n) - } + prog.tasksProgressBar.bar.IncrBy(n) prog.tasksProgressBar.tasksCount += int64(n) } @@ -209,7 +204,12 @@ func (bm *ProgressBarMng) IncBy(n int, prog *TasksWithHeadlineProg) { func (bm *ProgressBarMng) DoneTask(prog *TasksWithHeadlineProg) { bm.barsRWMutex.RLock() defer bm.barsRWMutex.RUnlock() - prog.tasksProgressBar.bar.SetCurrent(math.MaxInt64) + diff := prog.tasksProgressBar.total - prog.tasksProgressBar.tasksCount + // diff is int64, but we can increase the progress up to math.MaxInt in a time + for ; diff > math.MaxInt; diff -= math.MaxInt { + prog.tasksProgressBar.bar.IncrBy(math.MaxInt) + } + prog.tasksProgressBar.bar.IncrBy(int(diff)) } func (bm *ProgressBarMng) NewTasksProgressBar(totalTasks int64, windows bool, taskType string) *TasksProgressBar { @@ -240,7 +240,7 @@ func (bm *ProgressBarMng) newTasksProgressBar(getVal func() (numerator, denomina mpb.AppendDecorators( decor.Name(" "+headLine+": "), decor.Any(func(statistics decor.Statistics) string { - numeratorString := strconv.FormatInt(getProgressNumerator(statistics, *numerator, *denominator), 10) + numeratorString := strconv.Itoa(int(*numerator)) denominatorString := strconv.Itoa(int(*denominator)) return color.Green.Render(numeratorString + "/" + denominatorString) }), @@ -353,10 +353,3 @@ func setTerminalWidthVar() error { } return err } - -func getProgressNumerator(statistics decor.Statistics, numerator, denominator int64) int64 { - if statistics.Current == math.MaxInt64 { - return denominator - } - return numerator -} diff --git a/utils/progressbar/transferprogressbarmanager.go b/utils/progressbar/transferprogressbarmanager.go index d479998b4..340166dc2 100644 --- a/utils/progressbar/transferprogressbarmanager.go +++ b/utils/progressbar/transferprogressbarmanager.go @@ -1,7 +1,6 @@ package progressbar import ( - "math" "sync" "time" @@ -118,7 +117,7 @@ func (tpm *TransferProgressMng) NewPhase1ProgressBar() *TasksWithHeadlineProg { if tpm.currentRepoShouldStop { return } - transferredStorage, totalStorage, _, _, err := getVals() + ptr1, ptr2, _, _, err := getVals() if err != nil { log.Error("Error: Couldn't get needed information about transfer status from state") } @@ -127,10 +126,8 @@ func (tpm *TransferProgressMng) NewPhase1ProgressBar() *TasksWithHeadlineProg { return } if pb.GetTasksProgressBar() != nil { - pb.GetTasksProgressBar().SetGeneralProgressTotal(*totalStorage) - if pb.GetTasksProgressBar().GetBar().Current() < math.MaxInt64 { - pb.GetTasksProgressBar().GetBar().SetCurrent(*transferredStorage) - } + pb.GetTasksProgressBar().SetGeneralProgressTotal(*ptr2) + pb.GetTasksProgressBar().GetBar().SetCurrent(*ptr1) } time.Sleep(1 * time.Second) }