Skip to content

Commit 9ad4259

Browse files
committed
Add protected volume support to system prune command
1 parent 3717e2b commit 9ad4259

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

cmd/podman/system/prune.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ var (
3636
ValidArgsFunction: completion.AutocompleteNone,
3737
Example: `podman system prune`,
3838
}
39-
force bool
39+
force bool
40+
includeProtected bool
4041
)
4142

4243
func init() {
@@ -50,6 +51,7 @@ func init() {
5051
flags.BoolVar(&pruneOptions.External, "external", false, "Remove container data in storage not controlled by podman")
5152
flags.BoolVar(&pruneOptions.Build, "build", false, "Remove build containers")
5253
flags.BoolVar(&pruneOptions.Volume, "volumes", false, "Prune volumes")
54+
flags.BoolVar(&includeProtected, "include-protected", false, "Include protected volumes in prune operation")
5355
filterFlagName := "filter"
5456
flags.StringArrayVar(&filters, filterFlagName, []string{}, "Provide filter values (e.g. 'label=<key>=<value>')")
5557
_ = pruneCommand.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePruneFilters)
@@ -86,6 +88,11 @@ func prune(cmd *cobra.Command, args []string) error {
8688
if err != nil {
8789
return err
8890
}
91+
92+
// Set the include protected flag for volume pruning
93+
if pruneOptions.Volume {
94+
pruneOptions.VolumePruneOptions.IncludeProtected = includeProtected
95+
}
8996

9097
response, err := registry.ContainerEngine().SystemPrune(context.Background(), pruneOptions)
9198
if err != nil {
@@ -126,6 +133,11 @@ func prune(cmd *cobra.Command, args []string) error {
126133
}
127134

128135
func createPruneWarningMessage(pruneOpts entities.SystemPruneOptions) string {
136+
protectedNote := ""
137+
if pruneOpts.Volume && !pruneOpts.VolumePruneOptions.IncludeProtected {
138+
protectedNote = " (excluding protected volumes)"
139+
}
140+
129141
if pruneOpts.All {
130142
return `WARNING! This command removes:
131143
- all stopped containers
@@ -137,7 +149,7 @@ func createPruneWarningMessage(pruneOpts entities.SystemPruneOptions) string {
137149
}
138150
return `WARNING! This command removes:
139151
- all stopped containers
140-
- all networks not used by at least one container%s%s
152+
- all networks not used by at least one container%s%s` + protectedNote + `
141153
- all dangling images
142154
- all dangling build cache
143155

0 commit comments

Comments
 (0)