Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix podman load oci-archive's tar with name #7386

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(), ":")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the TrimSuffix do?

imgNameSli := strings.SplitN(imgName, ":", 2)
if len(imgNameSli) == 2 {
// Fixes: https://github.com/containers/podman/issues/7337
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still no answer to this.

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