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:
Sebastiaan van Stijn committed 2026-04-10 21:57:45 +02:00
1 parent 2200f277f9
commit 25ffdb23d9
1 file changed
+8 -5
+8 -5
View File
@@ -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
}
}