MCPcopy
hub / github.com/moby/moby / DiskUsage

Method DiskUsage

client/system_disk_usage.go:124–220  ·  view source on GitHub ↗

DiskUsage requests the current data usage from the daemon.

(ctx context.Context, options DiskUsageOptions)

Source from the content-addressed store, hash-verified

122
123// DiskUsage requests the current data usage from the daemon.
124func (cli *Client) DiskUsage(ctx context.Context, options DiskUsageOptions) (DiskUsageResult, error) {
125 query := url.Values{}
126
127 for _, t := range []struct {
128 flag bool
129 sysObj system.DiskUsageObject
130 }{
131 {options.Containers, system.ContainerObject},
132 {options.Images, system.ImageObject},
133 {options.Volumes, system.VolumeObject},
134 {options.BuildCache, system.BuildCacheObject},
135 } {
136 if t.flag {
137 query.Add("type", string(t.sysObj))
138 }
139 }
140
141 if options.Verbose {
142 query.Set("verbose", "1")
143 }
144
145 resp, err := cli.get(ctx, "/system/df", query, nil)
146 defer ensureReaderClosed(resp)
147 if err != nil {
148 return DiskUsageResult{}, err
149 }
150
151 if versions.LessThan(cli.version, "1.52") {
152 // Generate result from a legacy response.
153 var du legacyDiskUsage
154 if err := json.NewDecoder(resp.Body).Decode(&du); err != nil {
155 return DiskUsageResult{}, fmt.Errorf("retrieving disk usage: %v", err)
156 }
157
158 return diskUsageResultFromLegacyAPI(&du), nil
159 }
160
161 var du system.DiskUsage
162 if err := json.NewDecoder(resp.Body).Decode(&du); err != nil {
163 return DiskUsageResult{}, fmt.Errorf("retrieving disk usage: %v", err)
164 }
165
166 var r DiskUsageResult
167 if idu := du.ImageUsage; idu != nil {
168 r.Images = ImagesDiskUsage{
169 ActiveCount: idu.ActiveCount,
170 Reclaimable: idu.Reclaimable,
171 TotalCount: idu.TotalCount,
172 TotalSize: idu.TotalSize,
173 }
174
175 if options.Verbose {
176 r.Images.Items = slices.Clone(idu.Items)
177 }
178 }
179
180 if cdu := du.ContainerUsage; cdu != nil {
181 r.Containers = ContainersDiskUsage{

Callers

nothing calls this directly

Calls 8

getMethod · 0.95
ensureReaderClosedFunction · 0.85
ErrorfMethod · 0.80
AddMethod · 0.65
SetMethod · 0.65
DecodeMethod · 0.65
CloneMethod · 0.45

Tested by

no test coverage detected