Skip to content

Commit

Permalink
specifying --force,podman exit with 0
Browse files Browse the repository at this point in the history
Signed-off-by: wufan <[email protected]>
  • Loading branch information
aonoa committed Jun 30, 2022
1 parent 3426d56 commit 57bcd20
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/podman/containers/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
}
if setExit {
setExitCode(r.Err)
if rmOptions.Force && registry.GetExitCode() == 1 {
registry.SetExitCode(define.ExecErrorCodeIgnore)
}
}
errs = append(errs, r.Err)
} else {
Expand Down
5 changes: 4 additions & 1 deletion cmd/podman/images/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package images

import (
"fmt"

"github.com/containers/podman/v4/cmd/podman/common"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/errorhandling"
"github.com/pkg/errors"
Expand Down Expand Up @@ -82,6 +82,9 @@ func rm(cmd *cobra.Command, args []string) error {
}
}
registry.SetExitCode(report.ExitCode)
if imageOpts.Force && registry.GetExitCode() == 1 {
registry.SetExitCode(define.ExecErrorCodeIgnore)
}
}

return errorhandling.JoinErrors(rmErrors)
Expand Down
3 changes: 3 additions & 0 deletions cmd/podman/networks/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func networkRm(cmd *cobra.Command, args []string) error {
fmt.Println(r.Name)
} else {
setExitCode(r.Err)
if networkRmOptions.Force && registry.GetExitCode() == 1 {
registry.SetExitCode(define.ExecErrorCodeIgnore)
}
errs = append(errs, r.Err)
}
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/podman/pods/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs b
responses, err := registry.ContainerEngine().PodRm(context.Background(), namesOrIDs, rmOptions)
if err != nil {
setExitCode(err)
if rmOptions.Force && registry.GetExitCode() == 1 {
registry.SetExitCode(define.ExecErrorCodeIgnore)
}
return err
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func Execute() {
fmt.Fprintln(os.Stderr, "Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM")
}
}
if registry.GetExitCode() == define.ExecErrorCodeIgnore {
registry.SetExitCode(0)
}
fmt.Fprintln(os.Stderr, formatError(err))
}
os.Exit(registry.GetExitCode())
Expand Down
3 changes: 3 additions & 0 deletions cmd/podman/volumes/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func rm(cmd *cobra.Command, args []string) error {
fmt.Println(r.Id)
} else {
setExitCode(r.Err)
if rmOptions.Force && registry.GetExitCode() == 1 {
registry.SetExitCode(define.ExecErrorCodeIgnore)
}
errs = append(errs, r.Err)
}
}
Expand Down
2 changes: 2 additions & 0 deletions libpod/define/exec_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
ExecErrorCodeCannotInvoke = 126
// ExecErrorCodeNotFound is the error code to return when a command cannot be found
ExecErrorCodeNotFound = 127
// ExecErrorCodeIgnore is the error code to can be simply ignored
ExecErrorCodeIgnore = 128
)

// TranslateExecErrorToExitCode takes an error and checks whether it
Expand Down

0 comments on commit 57bcd20

Please sign in to comment.