mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
Merge pull request #2557 from QiWang19/filter2241
fix bug in podman images list all images with same name
This commit is contained in:
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
@ -128,7 +129,7 @@ func init() {
|
||||
func imagesCmd(c *cliconfig.ImagesValues) error {
|
||||
var (
|
||||
filterFuncs []imagefilters.ResultFilter
|
||||
newImage *adapter.ContainerImage
|
||||
image string
|
||||
)
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
@ -137,23 +138,23 @@ func imagesCmd(c *cliconfig.ImagesValues) error {
|
||||
}
|
||||
defer runtime.Shutdown(false)
|
||||
if len(c.InputArgs) == 1 {
|
||||
newImage, err = runtime.NewImageFromLocal(c.InputArgs[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
image = c.InputArgs[0]
|
||||
}
|
||||
|
||||
if len(c.InputArgs) > 1 {
|
||||
return errors.New("'podman images' requires at most 1 argument")
|
||||
}
|
||||
|
||||
if len(c.Filter) > 0 && image != "" {
|
||||
return errors.New("can not specify an image and a filter")
|
||||
}
|
||||
ctx := getContext()
|
||||
|
||||
if len(c.Filter) > 0 || newImage != nil {
|
||||
filterFuncs, err = CreateFilterFuncs(ctx, runtime, c.Filter, newImage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(c.Filter) > 0 {
|
||||
filterFuncs, err = CreateFilterFuncs(ctx, runtime, c.Filter, nil)
|
||||
} else {
|
||||
filterFuncs, err = CreateFilterFuncs(ctx, runtime, []string{fmt.Sprintf("reference=%s", image)}, nil)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opts := imagesOptions{
|
||||
@ -174,7 +175,7 @@ func imagesCmd(c *cliconfig.ImagesValues) error {
|
||||
|
||||
var filteredImages []*adapter.ContainerImage
|
||||
//filter the images
|
||||
if len(c.Filter) > 0 || newImage != nil {
|
||||
if len(c.Filter) > 0 || len(c.InputArgs) == 1 {
|
||||
filteredImages = imagefilters.FilterImages(images, filterFuncs)
|
||||
} else {
|
||||
filteredImages = images
|
||||
|
@ -112,6 +112,18 @@ var _ = Describe("Podman images", func() {
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(1))
|
||||
|
||||
session = podmanTest.Podman([]string{"tag", ALPINE, "foo:a"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
session = podmanTest.Podman([]string{"tag", BB, "foo:b"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"images", "-q", "foo"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(2))
|
||||
})
|
||||
|
||||
It("podman images filter reference", func() {
|
||||
|
@ -190,7 +190,7 @@ var _ = Describe("Podman load", func() {
|
||||
load.WaitWithDefaultTimeout()
|
||||
Expect(load.ExitCode()).To(Equal(0))
|
||||
|
||||
result := podmanTest.Podman([]string{"images", "-f", "label", "hello:world"})
|
||||
result := podmanTest.Podman([]string{"images", "hello:world"})
|
||||
result.WaitWithDefaultTimeout()
|
||||
Expect(result.LineInOutputContains("docker")).To(Not(BeTrue()))
|
||||
Expect(result.LineInOutputContains("localhost")).To(BeTrue())
|
||||
@ -216,7 +216,7 @@ var _ = Describe("Podman load", func() {
|
||||
load.WaitWithDefaultTimeout()
|
||||
Expect(load.ExitCode()).To(Equal(0))
|
||||
|
||||
result := podmanTest.Podman([]string{"images", "-f", "label", "hello:latest"})
|
||||
result := podmanTest.Podman([]string{"images", "hello:latest"})
|
||||
result.WaitWithDefaultTimeout()
|
||||
Expect(result.LineInOutputContains("docker")).To(Not(BeTrue()))
|
||||
Expect(result.LineInOutputContains("localhost")).To(BeTrue())
|
||||
@ -241,7 +241,7 @@ var _ = Describe("Podman load", func() {
|
||||
load.WaitWithDefaultTimeout()
|
||||
Expect(load.ExitCode()).To(Equal(0))
|
||||
|
||||
result := podmanTest.Podman([]string{"images", "-f", "label", "load:latest"})
|
||||
result := podmanTest.Podman([]string{"images", "load:latest"})
|
||||
result.WaitWithDefaultTimeout()
|
||||
Expect(result.LineInOutputContains("docker")).To(Not(BeTrue()))
|
||||
Expect(result.LineInOutputContains("localhost")).To(BeTrue())
|
||||
|
Reference in New Issue
Block a user