Skip to content

Commit

Permalink
fix podman load oci-archive's tar with name
Browse files Browse the repository at this point in the history
Signed-off-by: zhangguanzhang <[email protected]>
  • Loading branch information
zhangguanzhang committed Oct 4, 2020
1 parent 7c12967 commit 13b36ee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
18 changes: 18 additions & 0 deletions libpod/image/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion pkg/domain/infra/abi/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions test/system/120-load.bats
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ 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
fqin=localhost/$new_name:$new_tag
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
Expand Down

0 comments on commit 13b36ee

Please sign in to comment.