diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2022-07-26 06:41:08 -0400 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2022-07-26 16:00:42 -0400 |
commit | 75419c5d887e23f93a465311b02bb76d8cea1940 (patch) | |
tree | 1bce4f62fd40b7996561d608db8613b6db22fc77 /cmd/podman/images/rm.go | |
parent | 242639f4b1689231c37f909d3bda58b774a0ea96 (diff) | |
download | podman-75419c5d887e23f93a465311b02bb76d8cea1940.tar.gz podman-75419c5d887e23f93a465311b02bb76d8cea1940.tar.bz2 podman-75419c5d887e23f93a465311b02bb76d8cea1940.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/rm.go')
-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) } |