From 83f40de9652712baf84379f3292dc4f4f103ce50 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 28 Jul 2018 05:59:13 +0200 Subject: Introduce singlePullRefNameGoal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All but two cases returning a []*pullRefName only return a single item. Introduce a helper for that case, which seems not worth it now, but the return value will get a bit more complex and introducing the helper now will minimize code changes in future commits. Should not change behavior. Signed-off-by: Miloslav Trmač Closes: #1176 Approved by: rhatdan --- libpod/image/pull.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'libpod') diff --git a/libpod/image/pull.go b/libpod/image/pull.go index cfddb7e8d..276ccc898 100644 --- a/libpod/image/pull.go +++ b/libpod/image/pull.go @@ -62,6 +62,10 @@ type pullRefName struct { dstName string } +func singlePullRefNameGoal(rn *pullRefName) []*pullRefName { + return []*pullRefName{rn} +} + func getPullRefName(srcRef types.ImageReference, destName string) *pullRefName { imgPart, err := decompose(destName) if err == nil && !imgPart.hasRegistry { @@ -104,7 +108,7 @@ func refNamesFromImageReference(ctx context.Context, srcRef types.ImageReference if err != nil { return nil, err } - return []*pullRefName{getPullRefName(srcRef, reference)}, nil + return singlePullRefNameGoal(getPullRefName(srcRef, reference)), nil } if len(manifest[0].RepoTags) == 0 { @@ -113,7 +117,7 @@ func refNamesFromImageReference(ctx context.Context, srcRef types.ImageReference if err != nil { return nil, err } - return []*pullRefName{getPullRefName(srcRef, digest)}, nil + return singlePullRefNameGoal(getPullRefName(srcRef, digest)), nil } // Need to load in all the repo tags from the manifest @@ -142,7 +146,7 @@ func refNamesFromImageReference(ctx context.Context, srcRef types.ImageReference } else { dest = manifest.Annotations["org.opencontainers.image.ref.name"] } - return []*pullRefName{getPullRefName(srcRef, dest)}, nil + return singlePullRefNameGoal(getPullRefName(srcRef, dest)), nil case DirTransport: path := srcRef.StringWithinTransport() @@ -153,10 +157,10 @@ func refNamesFromImageReference(ctx context.Context, srcRef types.ImageReference // so docker.io isn't prepended, and the path becomes the repository image = DefaultLocalRepo + image } - return []*pullRefName{getPullRefName(srcRef, image)}, nil + return singlePullRefNameGoal(getPullRefName(srcRef, image)), nil default: - return []*pullRefName{getPullRefName(srcRef, imgName)}, nil + return singlePullRefNameGoal(getPullRefName(srcRef, imgName)), nil } } @@ -283,7 +287,7 @@ func refNamesFromPossiblyUnqualifiedName(inputName string) ([]*pullRefName, erro } else { ps.dstName = ps.image } - return []*pullRefName{&ps}, nil + return singlePullRefNameGoal(&ps), nil } searchRegistries, err := registries.GetRegistries() -- cgit v1.2.3-54-g00ecf