summaryrefslogtreecommitdiff
path: root/cmd/podman/volume_prune.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/volume_prune.go')
-rw-r--r--cmd/podman/volume_prune.go48
1 files changed, 26 insertions, 22 deletions
diff --git a/cmd/podman/volume_prune.go b/cmd/podman/volume_prune.go
index 652c50f42..41d95f9c7 100644
--- a/cmd/podman/volume_prune.go
+++ b/cmd/podman/volume_prune.go
@@ -2,12 +2,13 @@ package main
import (
"bufio"
+ "context"
"fmt"
"os"
"strings"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/libpod/adapter"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
@@ -37,21 +38,40 @@ var volumePruneCommand = cli.Command{
UseShortOptionHandling: true,
}
-func volumePruneCmd(c *cli.Context) error {
+func volumePrune(runtime *adapter.LocalRuntime, ctx context.Context) error {
var lastError error
+ volumes, err := runtime.GetAllVolumes()
+ if err != nil {
+ return err
+ }
+
+ for _, vol := range volumes {
+ err = runtime.RemoveVolume(ctx, vol, false, true)
+ if err == nil {
+ fmt.Println(vol.Name())
+ } else if err != libpod.ErrVolumeBeingUsed {
+ if lastError != nil {
+ logrus.Errorf("%q", lastError)
+ }
+ lastError = errors.Wrapf(err, "failed to remove volume %q", vol.Name())
+ }
+ }
+ return lastError
+}
+
+func volumePruneCmd(c *cli.Context) error {
+
if err := validateFlags(c, volumePruneFlags); err != nil {
return err
}
- runtime, err := libpodruntime.GetRuntime(c)
+ runtime, err := adapter.GetRuntime(c)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
- ctx := getContext()
-
// Prompt for confirmation if --force is not set
if !c.Bool("force") {
reader := bufio.NewReader(os.Stdin)
@@ -66,21 +86,5 @@ func volumePruneCmd(c *cli.Context) error {
}
}
- volumes, err := runtime.GetAllVolumes()
- if err != nil {
- return err
- }
-
- for _, vol := range volumes {
- err = runtime.RemoveVolume(ctx, vol, false, true)
- if err == nil {
- fmt.Println(vol.Name())
- } else if err != libpod.ErrVolumeBeingUsed {
- if lastError != nil {
- logrus.Errorf("%q", lastError)
- }
- lastError = errors.Wrapf(err, "failed to remove volume %q", vol.Name())
- }
- }
- return lastError
+ return volumePrune(runtime, getContext())
}