diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2022-07-26 06:41:08 -0400 |
---|---|---|
committer | Matthew Heon <mheon@redhat.com> | 2022-08-10 16:46:05 -0400 |
commit | 32848b95f6fcf9e8dcd51f23f43846d66886f1ac (patch) | |
tree | a3b5ece563a8cc7cc096eb0703f901279dc12a39 /cmd/podman/images | |
parent | 312bef288bd7b7cd2e52d25e4f5911f730fad4e8 (diff) | |
download | podman-32848b95f6fcf9e8dcd51f23f43846d66886f1ac.tar.gz podman-32848b95f6fcf9e8dcd51f23f43846d66886f1ac.tar.bz2 podman-32848b95f6fcf9e8dcd51f23f43846d66886f1ac.zip |
When removing objects specifying --force,podman should exit with 0
This Patch will cause podman COMMAND rm --force bogus not fail
This is how Docker works, so Podman should follow this to allow existing
scripts to convert from Docker to Podman.
Fixes: #14612
Oprignal version of this patch came from wufan 1991849113@qq.com
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd/podman/images')
-rw-r--r-- | cmd/podman/images/rm.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/cmd/podman/images/rm.go b/cmd/podman/images/rm.go index 18b22e51d..d3fd17440 100644 --- a/cmd/podman/images/rm.go +++ b/cmd/podman/images/rm.go @@ -3,11 +3,14 @@ package images import ( "errors" "fmt" + "strings" "github.com/containers/podman/v4/cmd/podman/common" "github.com/containers/podman/v4/cmd/podman/registry" + "github.com/containers/podman/v4/cmd/podman/utils" "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/errorhandling" + "github.com/containers/storage/types" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -81,8 +84,19 @@ func rm(cmd *cobra.Command, args []string) error { fmt.Println("Deleted: " + d) } } - registry.SetExitCode(report.ExitCode) + for _, err := range rmErrors { + if !imageOpts.Force || !strings.Contains(err.Error(), types.ErrImageUnknown.Error()) { + registry.SetExitCode(report.ExitCode) + } + } } - return errorhandling.JoinErrors(rmErrors) + var errs utils.OutputErrors + for _, err := range rmErrors { + if imageOpts.Force && strings.Contains(err.Error(), types.ErrImageUnknown.Error()) { + continue + } + errs = append(errs, err) + } + return errorhandling.JoinErrors(errs) } |