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)