aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-07-26 06:41:08 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2022-07-26 16:00:42 -0400
commit75419c5d887e23f93a465311b02bb76d8cea1940 (patch)
tree1bce4f62fd40b7996561d608db8613b6db22fc77 /cmd/podman
parent242639f4b1689231c37f909d3bda58b774a0ea96 (diff)
downloadpodman-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')
-rw-r--r--cmd/podman/containers/rm.go6
-rw-r--r--cmd/podman/images/rm.go18
-rw-r--r--cmd/podman/networks/rm.go6
-rw-r--r--cmd/podman/pods/rm.go7
-rw-r--r--cmd/podman/volumes/rm.go6
5 files changed, 40 insertions, 3 deletions
diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go
index 9fa688d23..056e32651 100644
--- a/cmd/podman/containers/rm.go
+++ b/cmd/podman/containers/rm.go
@@ -126,6 +126,9 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
var errs utils.OutputErrors
responses, err := registry.ContainerEngine().ContainerRm(context.Background(), namesOrIDs, rmOptions)
if err != nil {
+ if rmOptions.Force && strings.Contains(err.Error(), define.ErrNoSuchCtr.Error()) {
+ return nil
+ }
if setExit {
setExitCode(err)
}
@@ -136,6 +139,9 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
if errors.Is(r.Err, define.ErrWillDeadlock) {
logrus.Errorf("Potential deadlock detected - please run 'podman system renumber' to resolve")
}
+ if rmOptions.Force && strings.Contains(r.Err.Error(), define.ErrNoSuchCtr.Error()) {
+ continue
+ }
if setExit {
setExitCode(r.Err)
}
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)
}
diff --git a/cmd/podman/networks/rm.go b/cmd/podman/networks/rm.go
index c2d3f655f..d734b2867 100644
--- a/cmd/podman/networks/rm.go
+++ b/cmd/podman/networks/rm.go
@@ -63,6 +63,9 @@ func networkRm(cmd *cobra.Command, args []string) error {
}
responses, err := registry.ContainerEngine().NetworkRm(registry.Context(), args, networkRmOptions)
if err != nil {
+ if networkRmOptions.Force && strings.Contains(err.Error(), define.ErrNoSuchNetwork.Error()) {
+ return nil
+ }
setExitCode(err)
return err
}
@@ -70,6 +73,9 @@ func networkRm(cmd *cobra.Command, args []string) error {
if r.Err == nil {
fmt.Println(r.Name)
} else {
+ if networkRmOptions.Force && strings.Contains(r.Err.Error(), define.ErrNoSuchNetwork.Error()) {
+ continue
+ }
setExitCode(r.Err)
errs = append(errs, r.Err)
}
diff --git a/cmd/podman/pods/rm.go b/cmd/podman/pods/rm.go
index 2ffd968f9..0aa64481d 100644
--- a/cmd/podman/pods/rm.go
+++ b/cmd/podman/pods/rm.go
@@ -93,6 +93,9 @@ func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs b
responses, err := registry.ContainerEngine().PodRm(context.Background(), namesOrIDs, rmOptions)
if err != nil {
+ if rmOptions.Force && strings.Contains(err.Error(), define.ErrNoSuchPod.Error()) {
+ return nil
+ }
setExitCode(err)
return err
}
@@ -104,13 +107,15 @@ func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs b
fmt.Println(r.Id)
}
} else {
+ if rmOptions.Force && strings.Contains(r.Err.Error(), define.ErrNoSuchPod.Error()) {
+ continue
+ }
setExitCode(r.Err)
errs = append(errs, r.Err)
}
}
return errs.PrintErrors()
}
-
func setExitCode(err error) {
if errors.Is(err, define.ErrNoSuchPod) || strings.Contains(err.Error(), define.ErrNoSuchPod.Error()) {
registry.SetExitCode(1)
diff --git a/cmd/podman/volumes/rm.go b/cmd/podman/volumes/rm.go
index c160b8623..1383da279 100644
--- a/cmd/podman/volumes/rm.go
+++ b/cmd/podman/volumes/rm.go
@@ -65,6 +65,9 @@ func rm(cmd *cobra.Command, args []string) error {
}
responses, err := registry.ContainerEngine().VolumeRm(context.Background(), args, rmOptions)
if err != nil {
+ if rmOptions.Force && strings.Contains(err.Error(), define.ErrNoSuchVolume.Error()) {
+ return nil
+ }
setExitCode(err)
return err
}
@@ -72,6 +75,9 @@ func rm(cmd *cobra.Command, args []string) error {
if r.Err == nil {
fmt.Println(r.Id)
} else {
+ if rmOptions.Force && strings.Contains(r.Err.Error(), define.ErrNoSuchVolume.Error()) {
+ continue
+ }
setExitCode(r.Err)
errs = append(errs, r.Err)
}