From ecc1db39b53e0566aed7de7192db916cf44a9fcb Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Fri, 27 Jul 2018 02:56:57 +0200 Subject: Use srcRef.StringWithinTransport() instead of parsing imgName again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because srcRef is created by parsing imgName, both hard-code assumptions about transport-specific formats of the strings, so that is neither better nor worse; but we do less explicit parsing. Should not change behavior for dir:, nor for fully-correct docker-archive:. docker-archive:, though, also supports docker-archive:path:reference, where the reference is ignored (with a warning) on read; in such cases the previous code would use the reference only (not the path), the new code uses both as the path. Neither works, we just change the failure mode (but "error opening path:reference" is now more suggestive of the correct usage). Signed-off-by: Miloslav Trmač Closes: #1176 Approved by: rhatdan --- libpod/image/pull.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libpod/image/pull.go b/libpod/image/pull.go index 49a834391..b17b4434d 100644 --- a/libpod/image/pull.go +++ b/libpod/image/pull.go @@ -87,13 +87,12 @@ func getPullRefName(srcRef types.ImageReference, destName string) *pullRefName { // refNamesFromImageReference returns a list of pullRefName for a single ImageReference, depending on the used transport. func refNamesFromImageReference(ctx context.Context, srcRef types.ImageReference, imgName string, sc *types.SystemContext) ([]*pullRefName, error) { var pullNames []*pullRefName - splitArr := strings.Split(imgName, ":") - archFile := splitArr[len(splitArr)-1] // supports pulling from docker-archive, oci, and registries switch srcRef.Transport().Name() { case DockerArchive: - tarSource, err := tarfile.NewSourceFromFile(archFile) + archivePath := srcRef.StringWithinTransport() + tarSource, err := tarfile.NewSourceFromFile(archivePath) if err != nil { return nil, err } @@ -150,8 +149,8 @@ func refNamesFromImageReference(ctx context.Context, srcRef types.ImageReference pullInfo := getPullRefName(srcRef, dest) pullNames = append(pullNames, pullInfo) case DirTransport: - // supports pull from a directory - image := splitArr[1] + path := srcRef.StringWithinTransport() + image := path // remove leading "/" if image[:1] == "/" { // Instead of removing the leading /, set localhost as the registry -- cgit v1.2.3-54-g00ecf