MCPcopy Create free account
hub / github.com/containers/image / createProgressBar

Method createProgressBar

copy/progress_bars.go:58–118  ·  view source on GitHub ↗

createProgressBar creates a progressBar in pool. Note that if the copier's reportWriter is io.Discard, the progress bar's output will be discarded. Callers may call printCopyInfo() to print a single line instead. NOTE: Every progress bar created within a progress pool must either successfully com

(pool *mpb.Progress, partial bool, info types.BlobInfo, kind string, onComplete string)

Source from the content-addressed store, hash-verified

56// by convention, we don't leave progress bars in partial state when fully done
57// (even if we copied much less data than anticipated).
58func (c *copier) createProgressBar(pool *mpb.Progress, partial bool, info types.BlobInfo, kind string, onComplete string) (*progressBar, error) {
59 // shortDigestLen is the length of the digest used for blobs.
60 const shortDigestLen = 12
61
62 if err := info.Digest.Validate(); err != nil { // digest.Digest.Encoded() panics on failure, so validate explicitly.
63 return nil, err
64 }
65 prefix := fmt.Sprintf("Copying %s %s", kind, info.Digest.Encoded())
66 // Truncate the prefix (chopping of some part of the digest) to make all progress bars aligned in a column.
67 maxPrefixLen := len("Copying blob ") + shortDigestLen
68 if len(prefix) > maxPrefixLen {
69 prefix = prefix[:maxPrefixLen]
70 }
71
72 // onComplete will replace prefix once the bar/spinner has completed
73 onComplete = prefix + " " + onComplete
74
75 // Use a normal progress bar when we know the size (i.e., size > 0).
76 // Otherwise, use a spinner to indicate that something's happening.
77 var bar *mpb.Bar
78 if info.Size > 0 {
79 if partial {
80 bar = pool.AddBar(info.Size,
81 mpb.BarFillerClearOnComplete(),
82 mpb.PrependDecorators(
83 decor.OnComplete(decor.Name(prefix), onComplete),
84 ),
85 mpb.AppendDecorators(
86 decor.Any(customPartialBlobDecorFunc),
87 ),
88 )
89 } else {
90 bar = pool.AddBar(info.Size,
91 mpb.BarFillerClearOnComplete(),
92 mpb.PrependDecorators(
93 decor.OnComplete(decor.Name(prefix), onComplete),
94 ),
95 mpb.AppendDecorators(
96 decor.OnComplete(decor.CountersKibiByte("%.1f / %.1f"), ""),
97 decor.Name(" | "),
98 decor.OnComplete(decor.EwmaSpeed(decor.SizeB1024(0), "% .1f", 30), ""),
99 ),
100 )
101 }
102 } else {
103 bar = pool.New(0,
104 mpb.SpinnerStyle(".", "..", "...", "....", "").PositionLeft(),
105 mpb.BarFillerClearOnComplete(),
106 mpb.PrependDecorators(
107 decor.OnComplete(decor.Name(prefix), onComplete),
108 ),
109 mpb.AppendDecorators(
110 decor.OnComplete(decor.EwmaSpeed(decor.SizeB1024(0), "% .1f", 30), ""),
111 ),
112 )
113 }
114 return &progressBar{
115 Bar: bar,

Callers 2

copyConfigMethod · 0.80
copyLayerMethod · 0.80

Calls 1

NameMethod · 0.65

Tested by

no test coverage detected