summaryrefslogtreecommitdiff
path: root/pkg/domain/infra
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-12-09 08:46:44 -0500
committerGitHub <noreply@github.com>2020-12-09 08:46:44 -0500
commitb875c5c27c503108f1984256833a9a2da4d0c5d1 (patch)
tree9c663f0c33849394373810b12f3db2974c3efaae /pkg/domain/infra
parentae7f601649fd9d5e57ee0f6b0d35283bc4485259 (diff)
parenta59e2a1a114c039e1780aa2b08b9452dc569cdf4 (diff)
downloadpodman-b875c5c27c503108f1984256833a9a2da4d0c5d1.tar.gz
podman-b875c5c27c503108f1984256833a9a2da4d0c5d1.tar.bz2
podman-b875c5c27c503108f1984256833a9a2da4d0c5d1.zip
Merge pull request #8599 from rhatdan/prune
Repeat system pruning until there is nothing removed
Diffstat (limited to 'pkg/domain/infra')
-rw-r--r--pkg/domain/infra/abi/system.go76
1 files changed, 50 insertions, 26 deletions
diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go
index ec2532bea..7ed58092b 100644
--- a/pkg/domain/infra/abi/system.go
+++ b/pkg/domain/infra/abi/system.go
@@ -168,37 +168,61 @@ func checkInput() error { // nolint:deadcode,unused
// SystemPrune removes unused data from the system. Pruning pods, containers, volumes and images.
func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.SystemPruneOptions) (*entities.SystemPruneReport, error) {
var systemPruneReport = new(entities.SystemPruneReport)
- podPruneReport, err := ic.prunePodHelper(ctx)
- if err != nil {
- return nil, err
- }
- systemPruneReport.PodPruneReport = podPruneReport
-
- containerPruneReport, err := ic.pruneContainersHelper(nil)
- if err != nil {
- return nil, err
- }
- systemPruneReport.ContainerPruneReport = containerPruneReport
-
- results, err := ic.Libpod.ImageRuntime().PruneImages(ctx, options.All, nil)
- if err != nil {
- return nil, err
- }
- report := entities.ImagePruneReport{
- Report: entities.Report{
- Id: results,
- Err: nil,
- },
- }
+ found := true
+ for found {
+ found = false
+ podPruneReport, err := ic.prunePodHelper(ctx)
+ if err != nil {
+ return nil, err
+ }
+ if len(podPruneReport) > 0 {
+ found = true
+ }
+ systemPruneReport.PodPruneReport = append(systemPruneReport.PodPruneReport, podPruneReport...)
+ containerPruneReport, err := ic.pruneContainersHelper(nil)
+ if err != nil {
+ return nil, err
+ }
+ if len(containerPruneReport.ID) > 0 {
+ found = true
+ }
+ if systemPruneReport.ContainerPruneReport == nil {
+ systemPruneReport.ContainerPruneReport = containerPruneReport
+ } else {
+ for name, val := range containerPruneReport.ID {
+ systemPruneReport.ContainerPruneReport.ID[name] = val
+ }
+ }
- systemPruneReport.ImagePruneReport = &report
+ results, err := ic.Libpod.ImageRuntime().PruneImages(ctx, options.All, nil)
- if options.Volume {
- volumePruneReport, err := ic.pruneVolumesHelper(ctx)
if err != nil {
return nil, err
}
- systemPruneReport.VolumePruneReport = volumePruneReport
+ if len(results) > 0 {
+ found = true
+ }
+
+ if systemPruneReport.ImagePruneReport == nil {
+ systemPruneReport.ImagePruneReport = &entities.ImagePruneReport{
+ Report: entities.Report{
+ Id: results,
+ Err: nil,
+ },
+ }
+ } else {
+ systemPruneReport.ImagePruneReport.Report.Id = append(systemPruneReport.ImagePruneReport.Report.Id, results...)
+ }
+ if options.Volume {
+ volumePruneReport, err := ic.pruneVolumesHelper(ctx)
+ if err != nil {
+ return nil, err
+ }
+ if len(volumePruneReport) > 0 {
+ found = true
+ }
+ systemPruneReport.VolumePruneReport = append(systemPruneReport.VolumePruneReport, volumePruneReport...)
+ }
}
return systemPruneReport, nil
}