36
36
ValidArgsFunction : completion .AutocompleteNone ,
37
37
Example : `podman system prune` ,
38
38
}
39
- force bool
39
+ force bool
40
+ includeProtected bool
40
41
)
41
42
42
43
func init () {
@@ -50,6 +51,7 @@ func init() {
50
51
flags .BoolVar (& pruneOptions .External , "external" , false , "Remove container data in storage not controlled by podman" )
51
52
flags .BoolVar (& pruneOptions .Build , "build" , false , "Remove build containers" )
52
53
flags .BoolVar (& pruneOptions .Volume , "volumes" , false , "Prune volumes" )
54
+ flags .BoolVar (& includeProtected , "include-protected" , false , "Include protected volumes in prune operation" )
53
55
filterFlagName := "filter"
54
56
flags .StringArrayVar (& filters , filterFlagName , []string {}, "Provide filter values (e.g. 'label=<key>=<value>')" )
55
57
_ = pruneCommand .RegisterFlagCompletionFunc (filterFlagName , common .AutocompletePruneFilters )
@@ -86,6 +88,11 @@ func prune(cmd *cobra.Command, args []string) error {
86
88
if err != nil {
87
89
return err
88
90
}
91
+
92
+ // Set the include protected flag for volume pruning
93
+ if pruneOptions .Volume {
94
+ pruneOptions .VolumePruneOptions .IncludeProtected = includeProtected
95
+ }
89
96
90
97
response , err := registry .ContainerEngine ().SystemPrune (context .Background (), pruneOptions )
91
98
if err != nil {
@@ -126,6 +133,11 @@ func prune(cmd *cobra.Command, args []string) error {
126
133
}
127
134
128
135
func createPruneWarningMessage (pruneOpts entities.SystemPruneOptions ) string {
136
+ protectedNote := ""
137
+ if pruneOpts .Volume && ! pruneOpts .VolumePruneOptions .IncludeProtected {
138
+ protectedNote = " (excluding protected volumes)"
139
+ }
140
+
129
141
if pruneOpts .All {
130
142
return `WARNING! This command removes:
131
143
- all stopped containers
@@ -137,7 +149,7 @@ func createPruneWarningMessage(pruneOpts entities.SystemPruneOptions) string {
137
149
}
138
150
return `WARNING! This command removes:
139
151
- 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 + `
141
153
- all dangling images
142
154
- all dangling build cache
143
155
0 commit comments