summaryrefslogtreecommitdiff
path: root/cmd/podman/containers_prune.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/containers_prune.go')
-rw-r--r--cmd/podman/containers_prune.go37
1 files changed, 20 insertions, 17 deletions
diff --git a/cmd/podman/containers_prune.go b/cmd/podman/containers_prune.go
index 92604e82f..09141e9a3 100644
--- a/cmd/podman/containers_prune.go
+++ b/cmd/podman/containers_prune.go
@@ -1,9 +1,11 @@
package main
import (
- "github.com/containers/libpod/cmd/podman/libpodruntime"
+ "context"
+
"github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/libpod/adapter"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
@@ -25,20 +27,11 @@ var (
}
)
-func pruneContainersCmd(c *cli.Context) error {
- var (
- deleteFuncs []shared.ParallelWorkerInput
- )
-
- ctx := getContext()
- runtime, err := libpodruntime.GetRuntime(c)
- if err != nil {
- return errors.Wrapf(err, "could not get runtime")
- }
- defer runtime.Shutdown(false)
+func pruneContainers(runtime *adapter.LocalRuntime, ctx context.Context, maxWorkers int, force bool) error {
+ var deleteFuncs []shared.ParallelWorkerInput
filter := func(c *libpod.Container) bool {
- state, _ := c.State()
+ state, err := c.State()
if state == libpod.ContainerStateStopped || (state == libpod.ContainerStateExited && err == nil && c.PodID() == "") {
return true
}
@@ -54,7 +47,7 @@ func pruneContainersCmd(c *cli.Context) error {
for _, container := range delContainers {
con := container
f := func() error {
- return runtime.RemoveContainer(ctx, con, c.Bool("force"))
+ return runtime.RemoveContainer(ctx, con, force)
}
deleteFuncs = append(deleteFuncs, shared.ParallelWorkerInput{
@@ -62,13 +55,23 @@ func pruneContainersCmd(c *cli.Context) error {
ParallelFunc: f,
})
}
+ // Run the parallel funcs
+ deleteErrors, errCount := shared.ParallelExecuteWorkerPool(maxWorkers, deleteFuncs)
+ return printParallelOutput(deleteErrors, errCount)
+}
+
+func pruneContainersCmd(c *cli.Context) error {
+ runtime, err := adapter.GetRuntime(c)
+ if err != nil {
+ return errors.Wrapf(err, "could not get runtime")
+ }
+ defer runtime.Shutdown(false)
+
maxWorkers := shared.Parallelize("rm")
if c.GlobalIsSet("max-workers") {
maxWorkers = c.GlobalInt("max-workers")
}
logrus.Debugf("Setting maximum workers to %d", maxWorkers)
- // Run the parallel funcs
- deleteErrors, errCount := shared.ParallelExecuteWorkerPool(maxWorkers, deleteFuncs)
- return printParallelOutput(deleteErrors, errCount)
+ return pruneContainers(runtime, getContext(), maxWorkers, c.Bool("force"))
}