MCPcopy Index your code
hub / github.com/docker/cli / runPrune

Function runPrune

cli/command/system/prune.go:71–121  ·  view source on GitHub ↗
(ctx context.Context, dockerCli command.Cli, options pruneOptions)

Source from the content-addressed store, hash-verified

69Are you sure you want to continue?`
70
71func 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
123type cancelledErr struct{ error }
124

Callers 1

newPruneCommandFunction · 0.70

Calls 5

dryRunFunction · 0.85
InMethod · 0.65
OutMethod · 0.65
ListMethod · 0.65
pruneFnFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…