MCPcopy
hub / github.com/moby/moby / withFetchProgress

Function withFetchProgress

daemon/pkg/plugin/fetch_linux.go:198–293  ·  view source on GitHub ↗

withFetchProgress is a fetch handler which registers a descriptor with a progress

(cs content.Store, out progress.Output, ref reference.Named)

Source from the content-addressed store, hash-verified

196
197// withFetchProgress is a fetch handler which registers a descriptor with a progress
198func withFetchProgress(cs content.Store, out progress.Output, ref reference.Named) c8dimages.HandlerFunc {
199 return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
200 switch desc.MediaType {
201 case ocispec.MediaTypeImageManifest, c8dimages.MediaTypeDockerSchema2Manifest:
202 tn := reference.TagNameOnly(ref)
203 var tagOrDigest string
204 if tagged, ok := tn.(reference.Tagged); ok {
205 tagOrDigest = tagged.Tag()
206 } else {
207 tagOrDigest = tn.String()
208 }
209 progress.Messagef(out, tagOrDigest, "Pulling from %s", reference.FamiliarName(ref))
210 progress.Messagef(out, "", "Digest: %s", desc.Digest.String())
211 return nil, nil
212 case
213 c8dimages.MediaTypeDockerSchema2LayerGzip,
214 c8dimages.MediaTypeDockerSchema2Layer,
215 ocispec.MediaTypeImageLayer,
216 ocispec.MediaTypeImageLayerGzip:
217 default:
218 return nil, nil
219 }
220
221 id := stringid.TruncateID(desc.Digest.String())
222
223 if _, err := cs.Info(ctx, desc.Digest); err == nil {
224 out.WriteProgress(progress.Progress{ID: id, Action: "Already exists", LastUpdate: true})
225 return nil, nil
226 }
227
228 progress.Update(out, id, "Waiting")
229
230 key := remotes.MakeRefKey(ctx, desc)
231
232 go func() {
233 timer := time.NewTimer(100 * time.Millisecond)
234 if !timer.Stop() {
235 <-timer.C
236 }
237 defer timer.Stop()
238
239 var pulling bool
240 var (
241 // make sure we can still fetch from the content store
242 // if the main context is cancelled
243 // TODO: Might need to add some sort of timeout; see https://github.com/moby/moby/issues/49413
244 ctxErr error
245 noCancelCTX = context.WithoutCancel(ctx)
246 )
247
248 for {
249 timer.Reset(100 * time.Millisecond)
250
251 select {
252 case <-ctx.Done():
253 ctxErr = ctx.Err()
254 case <-timer.C:
255 }

Callers 1

fetchMethod · 0.85

Calls 12

MessagefFunction · 0.92
TruncateIDFunction · 0.92
UpdateFunction · 0.92
TagMethod · 0.80
StringMethod · 0.65
InfoMethod · 0.65
WriteProgressMethod · 0.65
ResetMethod · 0.65
StatusMethod · 0.65
StopMethod · 0.45
ErrMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…