| 1 | |
| 2 | |
| 3 | |
| 4 | @@ -157,6 +157,17 @@ |
| 5 | bar.Start() |
| 6 | defer bar.Finish() |
| 7 | reader := &downloadActivityReader{reader: resp.Body, timer: idle} |
| 8 | + // The desktop workbench consumes complete lines when stderr is a pipe. |
| 9 | + // Range responses count the bytes already present in the partial file. |
| 10 | + if os.Getenv("CAGE_SETUP_PROGRESS") == "1" { |
| 11 | + reader.received = offset |
| 12 | + reader.total = total |
| 13 | + reader.report = func(received, total int64) { |
| 14 | + fmt.Fprintf(os.Stderr, "CAGE_IMAGE_BYTES %d %d\n", received, total) |
| 15 | + } |
| 16 | + reader.report(offset, total) |
| 17 | + reader.lastReport = time.Now() |
| 18 | + } |
| 19 | n, err := io.Copy(out, bar.NewProxyReader(reader)) |
| 20 | if err != nil { |
| 21 | return true, err |
| 22 | @@ -172,6 +183,10 @@ |
| 23 | if total >= 0 && n+offset != total { |
| 24 | return true, io.ErrUnexpectedEOF |
| 25 | } |
| 26 | + if reader.report != nil { |
| 27 | + reader.report(reader.received, total) |
| 28 | + fmt.Fprintln(os.Stderr, "CAGE_IMAGE_VERIFY") |
| 29 | + } |
| 30 | if err := out.Sync(); err != nil { |
| 31 | return false, err |
| 32 | } |
| 33 | @@ -186,14 +201,24 @@ |
| 34 | } |
| 35 | |
| 36 | type downloadActivityReader struct { |
| 37 | - reader io.Reader |
| 38 | - timer *time.Timer |
| 39 | + reader io.Reader |
| 40 | + timer *time.Timer |
| 41 | + received, total int64 |
| 42 | + report func(int64, int64) |
| 43 | + lastReport time.Time |
| 44 | } |
| 45 | |
| 46 | func (r *downloadActivityReader) Read(p []byte) (int, error) { |
| 47 | n, err := r.reader.Read(p) |
| 48 | if n > 0 { |
| 49 | r.timer.Reset(time.Minute) |
| 50 | + if r.report != nil { |
| 51 | + r.received += int64(n) |
| 52 | + if time.Since(r.lastReport) >= time.Second { |
| 53 | + r.report(r.received, r.total) |
| 54 | + r.lastReport = time.Now() |
| 55 | + } |
| 56 | + } |
| 57 | } |
| 58 | return n, err |
| 59 | } |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | @@ -183,6 +183,9 @@ func Prepare(ctx context.Context, inst *limatype.Instance, guestAgent string) (* |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | + if os.Getenv("CAGE_SETUP_PROGRESS") == "1" { |
| 69 | + fmt.Fprintln(os.Stderr, "CAGE_IMAGE_READY") |
| 70 | + } |
| 71 | if err := limaDriver.CreateDisk(ctx); err != nil { |
| 72 | return nil, err |
| 73 | } |