Browse code

progress bar: don't strings.Repeat a negative number

Docker-DCO-1.1-Signed-off-by: Vincent Batts <vbatts@redhat.com> (github: vbatts)

Vincent Batts authored on 2014/07/29 01:01:43
Showing 1 changed files
... ...
@@ -50,7 +50,12 @@ func (p *JSONProgress) String() string {
50 50
 	total := units.HumanSize(int64(p.Total))
51 51
 	percentage := int(float64(p.Current)/float64(p.Total)*100) / 2
52 52
 	if width > 110 {
53
-		pbBox = fmt.Sprintf("[%s>%s] ", strings.Repeat("=", percentage), strings.Repeat(" ", 50-percentage))
53
+		// this number can't be negetive gh#7136
54
+		numSpaces := 0
55
+		if 50-percentage > 0 {
56
+			numSpaces = 50 - percentage
57
+		}
58
+		pbBox = fmt.Sprintf("[%s>%s] ", strings.Repeat("=", percentage), strings.Repeat(" ", numSpaces))
54 59
 	}
55 60
 	numbersBox = fmt.Sprintf("%8v/%v", current, total)
56 61