mirror of
https://github.com/containers/podman.git
synced 2025-06-20 09:03:43 +08:00
Fix podman rm to have correct exit codes
If you attempt to remove a running container is it supposed to exit with 2 If you attempt to remove a non existing container is is supposed to exit with 1 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@ -95,11 +95,9 @@ func rm(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
responses, err := registry.ContainerEngine().ContainerRm(context.Background(), args, rmOptions)
|
responses, err := registry.ContainerEngine().ContainerRm(context.Background(), args, rmOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO exitcode is a global main variable to track exit codes.
|
if len(args) < 2 {
|
||||||
// we need this enabled
|
setExitCode(err)
|
||||||
//if len(c.InputArgs) < 2 {
|
}
|
||||||
// exitCode = setExitCode(err)
|
|
||||||
//}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, r := range responses {
|
for _, r := range responses {
|
||||||
@ -108,6 +106,7 @@ func rm(cmd *cobra.Command, args []string) error {
|
|||||||
if errors.Cause(err) == define.ErrWillDeadlock {
|
if errors.Cause(err) == define.ErrWillDeadlock {
|
||||||
logrus.Errorf("Potential deadlock detected - please run 'podman system renumber' to resolve")
|
logrus.Errorf("Potential deadlock detected - please run 'podman system renumber' to resolve")
|
||||||
}
|
}
|
||||||
|
setExitCode(r.Err)
|
||||||
errs = append(errs, r.Err)
|
errs = append(errs, r.Err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(r.Id)
|
fmt.Println(r.Id)
|
||||||
@ -115,3 +114,13 @@ func rm(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
return errs.PrintErrors()
|
return errs.PrintErrors()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setExitCode(err error) {
|
||||||
|
cause := errors.Cause(err)
|
||||||
|
switch cause {
|
||||||
|
case define.ErrNoSuchCtr:
|
||||||
|
registry.SetExitCode(1)
|
||||||
|
case define.ErrCtrStateInvalid:
|
||||||
|
registry.SetExitCode(2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -17,7 +17,6 @@ var _ = Describe("Podman rm", func() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
Skip(v2fail)
|
|
||||||
tempdir, err = CreateTempDirInTempDir()
|
tempdir, err = CreateTempDirInTempDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
Reference in New Issue
Block a user