| 69 | Are you sure you want to continue?` |
| 70 | |
| 71 | func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) error { |
| 72 | // prune requires either force, or a user to confirm after prompting. |
| 73 | confirmed := options.force |
| 74 | |
| 75 | // Validate the given options for each pruner and construct a confirmation-message. |
| 76 | confirmationMessage, err := dryRun(ctx, dockerCli, options) |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | if !confirmed { |
| 81 | var err error |
| 82 | confirmed, err = prompt.Confirm(ctx, dockerCli.In(), dockerCli.Out(), confirmationMessage) |
| 83 | if err != nil { |
| 84 | return err |
| 85 | } |
| 86 | if !confirmed { |
| 87 | return cancelledErr{errors.New("system prune has been cancelled")} |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | var spaceReclaimed uint64 |
| 92 | for contentType, pruneFn := range pruner.List() { |
| 93 | switch contentType { |
| 94 | case pruner.TypeVolume: |
| 95 | if !options.pruneVolumes { |
| 96 | continue |
| 97 | } |
| 98 | case pruner.TypeContainer, pruner.TypeNetwork, pruner.TypeImage, pruner.TypeBuildCache: |
| 99 | // no special handling; keeping the "exhaustive" linter happy. |
| 100 | default: |
| 101 | // other pruners; no special handling; keeping the "exhaustive" linter happy. |
| 102 | } |
| 103 | |
| 104 | spc, output, err := pruneFn(ctx, dockerCli, pruner.PruneOptions{ |
| 105 | Confirmed: confirmed, |
| 106 | All: options.all, |
| 107 | Filter: options.filter, |
| 108 | }) |
| 109 | if err != nil && !errdefs.IsNotImplemented(err) { |
| 110 | return err |
| 111 | } |
| 112 | spaceReclaimed += spc |
| 113 | if output != "" { |
| 114 | _, _ = fmt.Fprintln(dockerCli.Out(), output) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | _, _ = fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) |
| 119 | |
| 120 | return nil |
| 121 | } |
| 122 | |
| 123 | type cancelledErr struct{ error } |
| 124 | |