From c13b8e3c9c1ed7a21dd43fa26729ecc6908170dd Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Wed, 25 Oct 2023 10:58:00 +0200 Subject: [PATCH] compat API: fix image-prune --all Docker deals with the --all flag on the client side while Podman does it on the server side. Hence, make sure to not set the dangling filter with two different values in the backend. Fixes: #20469 Signed-off-by: Valentin Rothberg --- pkg/domain/infra/abi/images.go | 13 ++++++++++++- test/apiv2/10-images.at | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go index 235f4db2a7..64695ad94b 100644 --- a/pkg/domain/infra/abi/images.go +++ b/pkg/domain/infra/abi/images.go @@ -56,7 +56,18 @@ func (ir *ImageEngine) Prune(ctx context.Context, opts entities.ImagePruneOption } if !opts.All { - pruneOptions.Filters = append(pruneOptions.Filters, "dangling=true") + // Issue #20469: Docker clients handle the --all flag on the + // client side by setting the dangling filter directly. + alreadySet := false + for _, filter := range pruneOptions.Filters { + if strings.HasPrefix(filter, "dangling=") { + alreadySet = true + break + } + } + if !alreadySet { + pruneOptions.Filters = append(pruneOptions.Filters, "dangling=true") + } } if opts.External { pruneOptions.Filters = append(pruneOptions.Filters, "containers=external") diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at index 1a3ee338d9..dba0eb3210 100644 --- a/test/apiv2/10-images.at +++ b/test/apiv2/10-images.at @@ -164,6 +164,8 @@ t DELETE libpod/images/test:test 200 t GET images/json?filters='{"label":["xyz"]}' 200 length=0 t GET libpod/images/json?filters='{"label":["xyz"]}' 200 length=0 +# Must not error out: #20469 +t POST images/prune?filters='{"dangling":["false"]}' 200 # to be used in prune until filter tests podman image build -t test1:latest -<