daemon: Daemon.imageDiskUsage: explicitly exclude "-1" for containers
The Containers field is set to "-1" if no information was collected; in
practice this should not happen when we collect diskusage information,
but let's be explicit.
Also rename the "i" variable to prevent it from being mistaken for the
slice's index value.
Follow-up to 46dba49ec8
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
1 file changed
+8
-5
@@ -78,12 +78,15 @@ func (daemon *Daemon) imageDiskUsage(ctx context.Context, verbose bool) (*backen
|
||||
TotalSize: totalSize,
|
||||
}
|
||||
|
||||
for _, i := range images {
|
||||
if i.Containers > 0 {
|
||||
for _, img := range images {
|
||||
switch {
|
||||
case img.Containers < 0:
|
||||
// No container-count information available; skip (assume it's in use).
|
||||
case img.Containers > 0:
|
||||
du.ActiveCount++
|
||||
} else if i.Size != -1 && i.SharedSize != -1 {
|
||||
// Only count reclaimable size if we have size information
|
||||
du.Reclaimable += (i.Size - i.SharedSize)
|
||||
case img.Containers == 0 && img.Size != -1 && img.SharedSize != -1:
|
||||
reclaimable := img.Size - img.SharedSize
|
||||
du.Reclaimable += reclaimable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user