summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-04-30 20:10:27 +0200
committerGitHub <noreply@github.com>2019-04-30 20:10:27 +0200
commite509eb25e7804c3d13e98fb6c788c739764016c4 (patch)
tree052396e79f9e099429e1aadd1afd34123fc4525e /cmd
parent75189d5b97d18d6b1a229e75d8427c85d2872d61 (diff)
parent1b2419ceb15b3c29b71c7d909ae143670d8a3a36 (diff)
downloadpodman-e509eb25e7804c3d13e98fb6c788c739764016c4.tar.gz
podman-e509eb25e7804c3d13e98fb6c788c739764016c4.tar.bz2
podman-e509eb25e7804c3d13e98fb6c788c739764016c4.zip
Merge pull request #2995 from jwhonce/wip/cleanup
Refactor container cleanup to use latest functions
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/cleanup.go39
1 files changed, 7 insertions, 32 deletions
diff --git a/cmd/podman/cleanup.go b/cmd/podman/cleanup.go
index 9434c68ba..4ff744ae5 100644
--- a/cmd/podman/cleanup.go
+++ b/cmd/podman/cleanup.go
@@ -1,11 +1,8 @@
package main
import (
- "fmt"
- "os"
-
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
+ "github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -49,38 +46,16 @@ func init() {
}
func cleanupCmd(c *cliconfig.CleanupValues) error {
- runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
+ runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
- cleanupContainers, lastError := getAllOrLatestContainers(&c.PodmanCommand, runtime, -1, "all")
-
- ctx := getContext()
-
- for _, ctr := range cleanupContainers {
- hadError := false
- if c.Remove {
- if err := runtime.RemoveContainer(ctx, ctr, false, true); err != nil {
- if lastError != nil {
- fmt.Fprintln(os.Stderr, lastError)
- }
- lastError = errors.Wrapf(err, "failed to cleanup and remove container %v", ctr.ID())
- hadError = true
- }
- } else {
- if err := ctr.Cleanup(ctx); err != nil {
- if lastError != nil {
- fmt.Fprintln(os.Stderr, lastError)
- }
- lastError = errors.Wrapf(err, "failed to cleanup container %v", ctr.ID())
- hadError = true
- }
- }
- if !hadError {
- fmt.Println(ctr.ID())
- }
+ ok, failures, err := runtime.CleanupContainers(getContext(), c)
+ if err != nil {
+ return err
}
- return lastError
+
+ return printCmdResults(ok, failures)
}