diff --git a/libpod/image/pull.go b/libpod/image/pull.go index 65acdf4278..b64686e3bd 100644 --- a/libpod/image/pull.go +++ b/libpod/image/pull.go @@ -201,6 +201,24 @@ func (ir *Runtime) pullGoalFromImageReference(ctx context.Context, srcRef types. }, nil case OCIArchive: + // imgName such as "/tmp/FOO.tar:" or "/tmp/FOO.tar:domain.com/foo:tag1" + imgName := strings.TrimSuffix(srcRef.StringWithinTransport(), ":") + imgNameSli := strings.SplitN(imgName, ":", 2) + if len(imgNameSli) == 2 { + // Fixes: https://github.com/containers/podman/issues/7337 + // use the empty name to test the manifest's length at first + testSrcRef, err := ociarchive.NewReference(imgNameSli[0], "") + if err != nil { + return nil, err + } + _, err = ociarchive.LoadManifestDescriptor(testSrcRef) + if err == nil { + // err is equal nil, this means the manifest's length is 1 + // so could use the name override it + return ir.getSinglePullRefPairGoal(testSrcRef, imgNameSli[1]) + } + } + // retrieve the manifest from index.json to access the image name manifest, err := ociarchive.LoadManifestDescriptor(srcRef) if err != nil { diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go index 965c63bec1..9c78b1c905 100644 --- a/pkg/domain/infra/abi/images.go +++ b/pkg/domain/infra/abi/images.go @@ -452,7 +452,11 @@ func (ir *ImageEngine) Load(ctx context.Context, opts entities.ImageLoadOptions) if !opts.Quiet { writer = os.Stderr } - name, err := ir.Libpod.LoadImage(ctx, opts.Name, opts.Input, writer, opts.SignaturePolicy) + iName := opts.Name + if opts.Tag != "" { + iName += ":" + opts.Tag + } + name, err := ir.Libpod.LoadImage(ctx, iName, opts.Input, writer, opts.SignaturePolicy) if err != nil { return nil, err } diff --git a/test/system/120-load.bats b/test/system/120-load.bats index 8ea9b1c69c..53d89bbf19 100644 --- a/test/system/120-load.bats +++ b/test/system/120-load.bats @@ -51,8 +51,7 @@ verify_iid_and_name() { run_podman images $fqin --format '{{.Repository}}:{{.Tag}}' is "$output" "$fqin" "image preserves name across save/load" - # FIXME: when/if 7337 gets fixed, load with a new tag - if false; then + # load with a new tag, when src file is oci-archive local new_name=x$(random_string 14 | tr A-Z a-z) local new_tag=t$(random_string 6 | tr A-Z a-z) run_podman rmi $fqin @@ -60,7 +59,6 @@ verify_iid_and_name() { run_podman load -i $archive $fqin run_podman images $fqin --format '{{.Repository}}:{{.Tag}}' is "$output" "$fqin" "image can be loaded with new name:tag" - fi # Clean up run_podman rmi $fqin