diff --git a/docs/source/markdown/options/filter.volume-ls.md b/docs/source/markdown/options/filter.volume-ls.md index af44b6dd416..9ad57c6c6ab 100644 --- a/docs/source/markdown/options/filter.volume-ls.md +++ b/docs/source/markdown/options/filter.volume-ls.md @@ -5,7 +5,9 @@ #### **--filter**, **-f**=*filter* Filter what volumes are shown in the output. -Multiple filters can be given with multiple uses of the --filter flag. + +The *filters* argument format is of `key=value`. If there is more than one *filter*, then pass multiple OPTIONS: **--filter** *foo=bar* **--filter** *bif=baz*. + Filters with the same key work inclusive, with the only exception being `label` which is exclusive. Filters with different keys always work exclusive. diff --git a/docs/source/markdown/podman-volume-prune.1.md b/docs/source/markdown/podman-volume-prune.1.md index 8b16ca35b12..40f58ee815a 100644 --- a/docs/source/markdown/podman-volume-prune.1.md +++ b/docs/source/markdown/podman-volume-prune.1.md @@ -27,6 +27,9 @@ Provide filter values. The *filters* argument format is of `key=value`. If there is more than one *filter*, then pass multiple OPTIONS: **--filter** *foo=bar* **--filter** *bif=baz*. +Filters with the same key work inclusive, with the only exception being `label` +which is exclusive. Filters with different keys always work exclusive. + Supported filters: | Filter | Description | diff --git a/libpod/runtime_volume.go b/libpod/runtime_volume.go index db64a85b400..b6e84d68f34 100644 --- a/libpod/runtime_volume.go +++ b/libpod/runtime_volume.go @@ -71,7 +71,7 @@ func (r *Runtime) HasVolume(name string) (bool, error) { // Volumes retrieves all volumes // Filters can be provided which will determine which volumes are included in the // output. If multiple filters are used, a volume will be returned if -// any of the filters are matched +// all of the filters are matched func (r *Runtime) Volumes(filters ...VolumeFilter) ([]*Volume, error) { if !r.valid { return nil, define.ErrRuntimeStopped @@ -88,9 +88,9 @@ func (r *Runtime) Volumes(filters ...VolumeFilter) ([]*Volume, error) { volsFiltered := make([]*Volume, 0, len(vols)) for _, vol := range vols { - include := false + include := true for _, filter := range filters { - include = include || filter(vol) + include = include && filter(vol) } if include { diff --git a/test/e2e/volume_ls_test.go b/test/e2e/volume_ls_test.go index 7a3a1eeb7a4..2566299c6cf 100644 --- a/test/e2e/volume_ls_test.go +++ b/test/e2e/volume_ls_test.go @@ -213,6 +213,13 @@ var _ = Describe("Podman volume ls", func() { Expect(session).Should(ExitCleanly()) Expect(session.OutputToStringArray()).To(HaveLen(1)) Expect(session.OutputToStringArray()[0]).To(Equal(vol3Name)) + + // Filters with different keys + session = podmanTest.Podman([]string{"volume", "ls", "-q", "--filter", "label=b=c", "--filter", "name=vol1"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + Expect(session.OutputToStringArray()).To(HaveLen(1)) + Expect(session.OutputToStringArray()[0]).To(Equal(vol1Name)) }) It("podman ls volume with --filter since/after", func() {