MCPcopy
hub / github.com/docker/compose / toPullProgressEvent

Function toPullProgressEvent

pkg/compose/pull.go:412–464  ·  pkg/compose/pull.go::toPullProgressEvent
(parent string, jm jsonstream.Message, events api.EventProcessor)

Source from the content-addressed store, hash-verified

410)
411
412func toPullProgressEvent(parent string, jm jsonstream.Message, events api.EventProcessor) {
413 if jm.ID == "" || jm.Progress == nil {
414 return
415 }
416
417 var (
418 details string
419 total int64
420 percent int
421 current int64
422 status = api.Working
423 )
424
425 switch jm.Status {
426 case PreparingPhase, WaitingPhase, PullingFsPhase:
427 percent = 0
428 case DownloadingPhase, ExtractingPhase, VerifyingChecksumPhase:
429 if jm.Progress != nil {
430 current = jm.Progress.Current
431 total = jm.Progress.Total
432 if jm.Progress.Total > 0 {
433 percent = min(int(jm.Progress.Current*100/jm.Progress.Total), 100)
434 }
435 }
436 case DownloadCompletePhase, AlreadyExistsPhase, PullCompletePhase:
437 status = api.Done
438 percent = 100
439 }
440
441 if strings.Contains(jm.Status, "Image is up to date") ||
442 strings.Contains(jm.Status, "Downloaded newer image") {
443 status = api.Done
444 percent = 100
445 }
446
447 if jm.Error != nil {
448 status = api.Error
449 details = jm.Error.Message
450 } else {
451 details = units.HumanSize(float64(jm.Progress.Current))
452 }
453
454 events.On(api.Resource{
455 ID: jm.ID,
456 ParentID: parent,
457 Current: current,
458 Total: total,
459 Percent: percent,
460 Status: status,
461 Text: jm.Status,
462 Details: details,
463 })
464}

Callers 1

pullServiceImageMethod · 0.85

Calls 1

OnMethod · 0.65

Tested by

no test coverage detected