From 25ffdb23d9a03d1da578cbc9ac139b4a7f39f623 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 4 Apr 2026 18:46:00 +0200 Subject: [PATCH] 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 46dba49ec8eff07a77f70479f4b32745e67a4e5d Signed-off-by: Sebastiaan van Stijn --- daemon/disk_usage.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/daemon/disk_usage.go b/daemon/disk_usage.go index 8acf1be42e..750cae540b 100644 --- a/daemon/disk_usage.go +++ b/daemon/disk_usage.go @@ -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 } }