From 5507f15ba58a271c018a5446ef091ee477b18b1d Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 28 Jul 2018 08:06:08 +0200 Subject: Replace Runtime.LoadFromArchive with Runtime.LoadFromArchiveReference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All callers of LoadFromArchive expect the input to be in the transport:name format, or create it that way. So, pass a types.ImageReference instead of a string. That requires us to add an explicit parse step in (podman pull); in (podman load) we can, instead of pasting strings, create native objects directly. Changes the error behavior of (podman pull), we no longer try heuristically parsing docker-archive:... inputs as Docker references. Also changes the string reported by (podman load) if all parsing attempts fail, to be only the path instead of dir:path. The error message itself is likely to be the same (from directory.Transport). (While at it, update a mismatched comment.) Signed-off-by: Miloslav Trmač Closes: #1176 Approved by: rhatdan --- cmd/podman/load.go | 26 ++++++++++++++++---------- cmd/podman/pull.go | 9 +++++++-- 2 files changed, 23 insertions(+), 12 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/load.go b/cmd/podman/load.go index fd3b317b7..ffef9f6a6 100644 --- a/cmd/podman/load.go +++ b/cmd/podman/load.go @@ -6,9 +6,11 @@ import ( "io/ioutil" "os" + "github.com/containers/image/directory" + dockerarchive "github.com/containers/image/docker/archive" + ociarchive "github.com/containers/image/oci/archive" "github.com/pkg/errors" "github.com/projectatomic/libpod/cmd/podman/libpodruntime" - "github.com/projectatomic/libpod/libpod" "github.com/projectatomic/libpod/libpod/image" "github.com/urfave/cli" ) @@ -104,20 +106,24 @@ func loadCmd(c *cli.Context) error { ctx := getContext() - src := libpod.DockerArchive + ":" + input - newImages, err := runtime.ImageRuntime().LoadFromArchive(ctx, src, c.String("signature-policy"), writer) + var newImages []*image.Image + src, err := dockerarchive.ParseReference(input) // FIXME? We should add dockerarchive.NewReference() + if err == nil { + newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.String("signature-policy"), writer) + } if err != nil { // generate full src name with specified image:tag - fullSrc := libpod.OCIArchive + ":" + input - if imageName != "" { - fullSrc = fullSrc + ":" + imageName + src, err := ociarchive.NewReference(input, imageName) // imageName may be "" + if err == nil { + newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.String("signature-policy"), writer) } - newImages, err = runtime.ImageRuntime().LoadFromArchive(ctx, fullSrc, c.String("signature-policy"), writer) if err != nil { - src = libpod.DirTransport + ":" + input - newImages, err = runtime.ImageRuntime().LoadFromArchive(ctx, src, c.String("signature-policy"), writer) + src, err := directory.NewReference(input) + if err == nil { + newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.String("signature-policy"), writer) + } if err != nil { - return errors.Wrapf(err, "error pulling %q", src) + return errors.Wrapf(err, "error pulling %q", input) } } } diff --git a/cmd/podman/pull.go b/cmd/podman/pull.go index d8fcf05c2..90fb1345a 100644 --- a/cmd/podman/pull.go +++ b/cmd/podman/pull.go @@ -6,6 +6,7 @@ import ( "os" "strings" + "github.com/containers/image/transports/alltransports" "github.com/containers/image/types" "github.com/pkg/errors" "github.com/projectatomic/libpod/cmd/podman/libpodruntime" @@ -110,9 +111,13 @@ func pullCmd(c *cli.Context) error { forceSecure = c.Bool("tls-verify") } - // Possible for docker-archive to have multiple tags, so use NewFromLoad instead + // Possible for docker-archive to have multiple tags, so use LoadFromArchiveReference instead if strings.HasPrefix(image, libpod.DockerArchive+":") { - newImage, err := runtime.ImageRuntime().LoadFromArchive(getContext(), image, c.String("signature-policy"), writer) + srcRef, err := alltransports.ParseImageName(image) + if err != nil { + return errors.Wrapf(err, "error parsing %q", image) + } + newImage, err := runtime.ImageRuntime().LoadFromArchiveReference(getContext(), srcRef, c.String("signature-policy"), writer) if err != nil { return errors.Wrapf(err, "error pulling image from %q", image) } -- cgit v1.2.3-54-g00ecf