From 775eb78f6ba96a19f16e2f96fc7d2ee402049a3b Mon Sep 17 00:00:00 2001
From: Miloslav Trmač <mitr@redhat.com>
Date: Wed, 18 Jul 2018 23:20:36 +0200
Subject: Introduce nameToPull, move shaPullName in there
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

shaPullName is only used internally in createNamesToPull; so, introduce
a nameToPull as a variant of pullStruct which has shaPullName (and does not
have destRef).

Eventually, we want to split pullStruct preparation into easily-testable
store-independent name preparation, and a store-dependent and difficult-to-test
but trivial conversion using StorageTransport.ParseStoreReference.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1112
Approved by: rhatdan
---
 libpod/image/pull.go | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

(limited to 'libpod')

diff --git a/libpod/image/pull.go b/libpod/image/pull.go
index cb2de8fc2..f1bfac2a3 100644
--- a/libpod/image/pull.go
+++ b/libpod/image/pull.go
@@ -50,11 +50,11 @@ var (
 	DefaultLocalRepo = "localhost"
 )
 
+// pullStruct records a pair of prepared image references to try to pull (if not DockerArchive) or to pull all (if DockerArchive)
 type pullStruct struct {
-	image       string
-	srcRef      types.ImageReference
-	dstRef      types.ImageReference
-	shaPullName string
+	image  string
+	srcRef types.ImageReference
+	dstRef types.ImageReference
 }
 
 func (ir *Runtime) getPullStruct(srcRef types.ImageReference, destName string) (*pullStruct, error) {
@@ -257,11 +257,18 @@ func (i *Image) pullImage(ctx context.Context, writer io.Writer, authfile, signa
 	return images, nil
 }
 
+// nameToPull is a mapping between a resolved source and an expected store destination name (FIXME: clean up somehow?)
+type nameToPull struct {
+	image       string
+	srcRef      types.ImageReference
+	shaPullName string
+}
+
 // createNamesToPull looks at a decomposed image and determines the possible
 // images names to try pulling in combination with the registries.conf file as well
 func (i *Image) createNamesToPull() ([]*pullStruct, error) {
 	var (
-		pullNames []*pullStruct
+		pullNames []*nameToPull
 		imageName string
 	)
 
@@ -279,7 +286,7 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
 		if err != nil {
 			return nil, errors.Wrapf(err, "unable to parse '%s'", i.InputName)
 		}
-		ps := pullStruct{
+		ps := nameToPull{
 			image:  i.InputName,
 			srcRef: srcRef,
 		}
@@ -303,7 +310,7 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
 			if err != nil {
 				return nil, errors.Wrapf(err, "unable to parse '%s'", i.InputName)
 			}
-			ps := pullStruct{
+			ps := nameToPull{
 				image:  decomposedImage.assemble(),
 				srcRef: srcRef,
 			}
@@ -311,8 +318,9 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
 		}
 	}
 
-	// Here we construct the destination reference
-	for _, pStruct := range pullNames {
+	// Here we construct the destination references
+	res := make([]*pullStruct, len(pullNames))
+	for j, pStruct := range pullNames {
 		dstName := pStruct.image
 		if pStruct.shaPullName != "" {
 			dstName = pStruct.shaPullName
@@ -321,8 +329,11 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
 		if err != nil {
 			return nil, errors.Wrapf(err, "error parsing dest reference name")
 		}
-		pStruct.dstRef = destRef
+		res[j] = &pullStruct{
+			image:  pStruct.image,
+			srcRef: pStruct.srcRef,
+			dstRef: destRef,
+		}
 	}
-
-	return pullNames, nil
+	return res, nil
 }
-- 
cgit v1.2.3-54-g00ecf