From 190e0744599e972e4a00ef3a9184cd82c87b5282 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 28 Jul 2018 02:58:56 +0200 Subject: Remove the :// end from DockerTransport MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (... but keep it in DefaultTransport, which remains irregular.) This makes DockerTransport consistent with the others, and much more importantly, allows several instances to do > imgRef.Transport().Name() == DockerTransport instead of the current > strings.HasPrefix(DockerTransport, imgRef.Transport().Name()) , which currently works but is pretty nonsensical (it does not check the "docker://" prefix against the _full reference_, but it checks the _transport name_ as a prefix of "docker://", i.e. a transport named "d" would be accepted. Should not change behavior, because the only currently existing transport which has a name that is a prefix of "docker://" is c/image/docker.Transport (but does not add unit tests). Signed-off-by: Miloslav Trmač Closes: #1176 Approved by: rhatdan --- libpod/image/image.go | 2 +- libpod/image/pull.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libpod/image/image.go b/libpod/image/image.go index 112eeb015..914b8f754 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -551,7 +551,7 @@ func (i *Image) PushImage(ctx context.Context, destination, manifestMIMEType, au return err } copyOptions := getCopyOptions(writer, signaturePolicyPath, nil, dockerRegistryOptions, signingOptions, authFile, manifestMIMEType, forceCompress, additionalDockerArchiveTags) - if strings.HasPrefix(DockerTransport, dest.Transport().Name()) { + if dest.Transport().Name() == DockerTransport { imgRef, err := reference.Parse(dest.DockerReference().String()) if err != nil { return err diff --git a/libpod/image/pull.go b/libpod/image/pull.go index 269b73d08..69c7de6ff 100644 --- a/libpod/image/pull.go +++ b/libpod/image/pull.go @@ -38,14 +38,14 @@ var ( // and creating a filesystem image TarballTransport = tarball.Transport.Name() // DockerTransport is the transport for docker registries - DockerTransport = docker.Transport.Name() + "://" + DockerTransport = docker.Transport.Name() // AtomicTransport is the transport for atomic registries AtomicTransport = "atomic" // DefaultTransport is a prefix that we apply to an image name // NOTE: This is a string prefix, not actually a transport name usable for transports.Get(); // and because syntaxes of image names are transport-dependent, the prefix is not really interchangeable; // each user implicitly assumes the appended string is a Docker-like reference. - DefaultTransport = DockerTransport + DefaultTransport = DockerTransport + "://" // DefaultLocalRepo is the default local repository for local image operations // Remote pulls will still use defined registries DefaultLocalRepo = "localhost" @@ -206,7 +206,7 @@ func (i *Image) pullImage(ctx context.Context, writer io.Writer, authfile, signa var images []string for _, imageInfo := range pullRefPairs { copyOptions := getCopyOptions(writer, signaturePolicyPath, dockerOptions, nil, signingOptions, authfile, "", false, nil) - if strings.HasPrefix(DockerTransport, imageInfo.srcRef.Transport().Name()) { + if imageInfo.srcRef.Transport().Name() == DockerTransport { imgRef, err := reference.Parse(imageInfo.srcRef.DockerReference().String()) if err != nil { return nil, err @@ -219,7 +219,7 @@ func (i *Image) pullImage(ctx context.Context, writer io.Writer, authfile, signa } } // Print the following statement only when pulling from a docker or atomic registry - if writer != nil && (strings.HasPrefix(DockerTransport, imageInfo.srcRef.Transport().Name()) || imageInfo.srcRef.Transport().Name() == AtomicTransport) { + if writer != nil && (imageInfo.srcRef.Transport().Name() == DockerTransport || imageInfo.srcRef.Transport().Name() == AtomicTransport) { io.WriteString(writer, fmt.Sprintf("Trying to pull %s...", imageInfo.image)) } if err = cp.Image(ctx, policyContext, imageInfo.dstRef, imageInfo.srcRef, copyOptions); err != nil { -- cgit v1.2.3-54-g00ecf