Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/podman/volumes/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package volumes
import (
"bufio"
"context"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -64,6 +65,11 @@ func prune(cmd *cobra.Command, _ []string) error {

// --all adds filter all=true (Docker-compatible; behavior is filter-only)
allFlag, _ := cmd.Flags().GetBool("all")
filterAllFlag := strings.EqualFold(pruneOptions.Filters.Get("all"), "true")
if allFlag && filterAllFlag {
return errors.New("--all and --filter all cannot be used together")
}
allFlag = allFlag || filterAllFlag
if allFlag {
pruneOptions.Filters.Set("all", "true")
}
Expand All @@ -79,6 +85,7 @@ func prune(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
delete(listOptions.Filter, "all") // list does not support --filter all
filteredVolumes, err := registry.ContainerEngine().VolumeList(context.Background(), listOptions)
if err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/volume_prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ var _ = Describe("Podman volume prune", func() {
Expect(session.OutputToString()).To(ContainSubstring("named_vol"))
})

It("podman volume prune --all removes all unused volumes", func() {
podmanTest.PodmanExitCleanly("volume", "create", "prune_all_test")
podmanTest.PodmanExitCleanly("volume", "prune", "--all", "--force")

session := podmanTest.PodmanExitCleanly("volume", "ls")
Expect(session.OutputToStringArray()).To(HaveLen(1))
})

It("podman volume prune --filter all=true removes all unused volumes", func() {
podmanTest.PodmanExitCleanly("volume", "create", "prune_filter_all_test")
podmanTest.PodmanExitCleanly("volume", "prune", "--filter", "all=true", "--force")
Expand All @@ -50,6 +58,10 @@ var _ = Describe("Podman volume prune", func() {
Expect(session.OutputToStringArray()).To(HaveLen(1))
})

It("podman volume prune --filter all=true does not crash without --force", func() {
podmanTest.PodmanExitCleanly("volume", "prune", "--filter", "all=true")
})

It("podman prune volume --filter until", func() {
podmanTest.PodmanExitCleanly("volume", "create", "--label", "label1=value1", "myvol1")

Expand Down