From 7e38b37e7ca37a416f3e6f30459379e33b8a9891 Mon Sep 17 00:00:00 2001 From: Wang Long Date: Tue, 27 Sep 2016 17:50:13 +0800 Subject: [PATCH] Delete: exit with non zero if one of the containers encountered an error Signed-off-by: Wang Long --- delete.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/delete.go b/delete.go index d2e73a72..52ca2390 100644 --- a/delete.go +++ b/delete.go @@ -45,6 +45,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for }, }, Action: func(context *cli.Context) error { + hasError := false if !context.Args().Present() { return fmt.Errorf("runc: \"delete\" requires a minimum of 1 argument") } @@ -65,11 +66,13 @@ status of "ubuntu01" as "stopped" the following will delete resources held for } fmt.Fprintf(os.Stderr, "container %s is not exist\n", id) } + hasError = true continue } s, err := container.Status() if err != nil { fmt.Fprintf(os.Stderr, "status for %s: %v\n", id, err) + hasError = true continue } switch s { @@ -79,18 +82,25 @@ status of "ubuntu01" as "stopped" the following will delete resources held for err := killContainer(container) if err != nil { fmt.Fprintf(os.Stderr, "kill container %s: %v\n", id, err) + hasError = true } default: if context.Bool("force") { err := killContainer(container) if err != nil { fmt.Fprintf(os.Stderr, "kill container %s: %v\n", id, err) + hasError = true } } else { fmt.Fprintf(os.Stderr, "cannot delete container %s that is not stopped: %s\n", id, s) + hasError = true } } } + + if hasError { + return fmt.Errorf("one or more of the container deletions failed") + } return nil }, }