Browse code

Merge pull request #3287 from vieux/fix_progressbar_display_push

fix progressbar in docker push

Michael Crosby authored on 2014/01/03 06:38:11
Showing 4 changed files
... ...
@@ -448,6 +448,11 @@ func (r *Registry) PushImageLayerRegistry(imgID string, layer io.Reader, registr
448 448
 	if err != nil {
449 449
 		return "", fmt.Errorf("Failed to upload layer: %s", err)
450 450
 	}
451
+	if rc, ok := layer.(io.Closer); ok {
452
+		if err := rc.Close(); err != nil {
453
+			return "", err
454
+		}
455
+	}
451 456
 	defer res.Body.Close()
452 457
 
453 458
 	if res.StatusCode != 200 {
... ...
@@ -1284,6 +1284,7 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgID,
1284 1284
 		return "", err
1285 1285
 	}
1286 1286
 
1287
+	out.Write(sf.FormatProgress(utils.TruncateID(imgData.ID), "Image successfully pushed", nil))
1287 1288
 	return imgData.Checksum, nil
1288 1289
 }
1289 1290
 
... ...
@@ -52,7 +52,7 @@ func (p *JSONProgress) String() string {
52 52
 	}
53 53
 	numbersBox = fmt.Sprintf("%8v/%v", current, total)
54 54
 
55
-	if p.Start > 0 {
55
+	if p.Start > 0 && percentage < 50 {
56 56
 		fromStart := time.Now().UTC().Sub(time.Unix(int64(p.Start), 0))
57 57
 		perEntry := fromStart / time.Duration(p.Current)
58 58
 		left := time.Duration(p.Total-p.Current) * perEntry
... ...
@@ -7,21 +7,18 @@ import (
7 7
 
8 8
 // Reader with progress bar
9 9
 type progressReader struct {
10
-	reader   io.ReadCloser // Stream to read from
11
-	output   io.Writer     // Where to send progress bar to
12
-	progress JSONProgress
13
-	//	readTotal    int    // Expected stream length (bytes)
14
-	//	readProgress int    // How much has been read so far (bytes)
10
+	reader     io.ReadCloser // Stream to read from
11
+	output     io.Writer     // Where to send progress bar to
12
+	progress   JSONProgress
15 13
 	lastUpdate int // How many bytes read at least update
16 14
 	ID         string
17 15
 	action     string
18
-	//	template   string // Template to print. Default "%v/%v (%v)"
19
-	sf      *StreamFormatter
20
-	newLine bool
16
+	sf         *StreamFormatter
17
+	newLine    bool
21 18
 }
22 19
 
23 20
 func (r *progressReader) Read(p []byte) (n int, err error) {
24
-	read, err := io.ReadCloser(r.reader).Read(p)
21
+	read, err := r.reader.Read(p)
25 22
 	r.progress.Current += read
26 23
 	updateEvery := 1024 * 512 //512kB
27 24
 	if r.progress.Total > 0 {
... ...
@@ -41,7 +38,9 @@ func (r *progressReader) Read(p []byte) (n int, err error) {
41 41
 	return read, err
42 42
 }
43 43
 func (r *progressReader) Close() error {
44
-	return io.ReadCloser(r.reader).Close()
44
+	r.progress.Current = r.progress.Total
45
+	r.output.Write(r.sf.FormatProgress(r.ID, r.action, &r.progress))
46
+	return r.reader.Close()
45 47
 }
46 48
 func ProgressReader(r io.ReadCloser, size int, output io.Writer, sf *StreamFormatter, newline bool, ID, action string) *progressReader {
47 49
 	return &progressReader{