Replace Runtime.LoadFromArchive with Runtime.LoadFromArchiveReference

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č <mitr@redhat.com>

Closes: #1176
Approved by: rhatdan
This commit is contained in:
Miloslav Trmač
2018-07-28 08:06:08 +02:00
committed by Atomic Bot
parent 04f3a9079c
commit 5507f15ba5
3 changed files with 27 additions and 16 deletions

View File

@@ -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)
}