MCPcopy
hub / github.com/containers/toolbox / showPromptForDownloadFirst

Function showPromptForDownloadFirst

src/cmd/create.go:768–833  ·  view source on GitHub ↗
(imageFull string)

Source from the content-addressed store, hash-verified

766}
767
768func showPromptForDownloadFirst(imageFull string) (bool, error) {
769 prompt := createPromptForDownload(imageFull, " ... MB")
770
771 parentCtx := context.Background()
772 askCtx, askCancel := context.WithCancelCause(parentCtx)
773 defer askCancel(errors.New("clean-up"))
774
775 askCh, askErrCh := askForConfirmationAsync(askCtx, prompt, nil)
776
777 imageSizeCtx, imageSizeCancel := context.WithCancelCause(parentCtx)
778 defer imageSizeCancel(errors.New("clean-up"))
779
780 imageSizeCh, imageSizeErrCh := getImageSizeFromRegistryAsync(imageSizeCtx, imageFull)
781
782 var imageSize string
783 var shouldPullImage bool
784
785 select {
786 case val := <-askCh:
787 shouldPullImage = val
788 cause := fmt.Errorf("%w: received confirmation without image size", context.Canceled)
789 imageSizeCancel(cause)
790 case err := <-askErrCh:
791 shouldPullImage = false
792 cause := fmt.Errorf("failed to ask for confirmation without image size: %w", err)
793 imageSizeCancel(cause)
794 case val := <-imageSizeCh:
795 imageSize = val
796 cause := fmt.Errorf("%w: received image size", context.Canceled)
797 askCancel(cause)
798 case err := <-imageSizeErrCh:
799 cause := fmt.Errorf("failed to get image size: %w", err)
800 askCancel(cause)
801 }
802
803 if imageSizeCtx.Err() != nil && askCtx.Err() == nil {
804 cause := context.Cause(imageSizeCtx)
805 logrus.Debugf("Show prompt for download: image size canceled: %s", cause)
806 return shouldPullImage, nil
807 }
808
809 var done bool
810
811 if imageSizeCtx.Err() == nil && askCtx.Err() != nil {
812 select {
813 case val := <-askCh:
814 logrus.Debugf("Show prompt for download: received pending confirmation without image size")
815 shouldPullImage = val
816 done = true
817 case err := <-askErrCh:
818 logrus.Debugf("Show prompt for download: failed to ask for confirmation without image size: %s",
819 err)
820 }
821 } else {
822 panic("code should not be reached")
823 }
824
825 cause := context.Cause(askCtx)

Callers 1

showPromptForDownloadFunction · 0.85

Calls 3

createPromptForDownloadFunction · 0.85
askForConfirmationAsyncFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…