From 415668c802cb9988e856e56de5de1862fd746cb3 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 28 May 2025 16:25:53 +0200 Subject: [PATCH] system df --verbose don't crash When a container has no image, i.e. using rootfs like our new infra containers then the Image function crashed trying to show the first 12 image ID chars. If there is no image simply show nothing there. Fixes: #26224 Signed-off-by: Paul Holzinger --- cmd/podman/system/df.go | 5 ++++- test/system/320-system-df.bats | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/podman/system/df.go b/cmd/podman/system/df.go index 7c7f69efc9..c3553a5399 100644 --- a/cmd/podman/system/df.go +++ b/cmd/podman/system/df.go @@ -275,7 +275,10 @@ func (d *dfContainer) ContainerID() string { } func (d *dfContainer) Image() string { - return d.SystemDfContainerReport.Image[0:12] + if len(d.SystemDfContainerReport.Image) >= 12 { + return d.SystemDfContainerReport.Image[0:12] + } + return "" } func (d *dfContainer) Command() string { diff --git a/test/system/320-system-df.bats b/test/system/320-system-df.bats index a0e53f4df1..eff8575e64 100644 --- a/test/system/320-system-df.bats +++ b/test/system/320-system-df.bats @@ -34,6 +34,23 @@ function setup_file() { is "$output" '.*"Local Volumes".*"Size":"0B"' "Total containers reported" } +# Regression test for https://github.com/containers/podman/issues/26224 +@test "podman system df - with rootfs container" { + pod=p-$(safename) + # create a pod which creates an infra container based on a rootfs + run_podman pod create --name $pod + + run_podman system df + assert "${lines[1]}" =~ "Images *1 *0.*" + assert "${lines[2]}" =~ "Containers *1 *0.*" + run_podman system df --verbose + assert "${lines[5]}" =~ \ + "[0-9a-f]{12} *0.*[0-9a-f]{12}-infra" \ + "system df --verbose, 'Containers', infra line" + + run_podman pod rm -f $pod +} + @test "podman system df --format json functionality" { # Run two dummy containers, one which exits, one which stays running cname_stopped=c-stopped-$(safename)