Use srcRef.StringWithinTransport() instead of parsing imgName again

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

Closes: #1176
Approved by: rhatdan
This commit is contained in:
Miloslav Trmač
2018-07-27 02:56:57 +02:00
committed by Atomic Bot
parent 24da27c3e9
commit ecc1db39b5

View File

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