diff options
author | Paul Holzinger <paul.holzinger@web.de> | 2020-07-19 22:55:27 +0200 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2020-07-22 13:49:58 -0400 |
commit | 2e35dfa20c60a80ca12ffab68a7fcdac797feb3d (patch) | |
tree | cf96be7bbe2cf29a330277f2425f4206813d66aa | |
parent | 7461bafabba1dae736081de61baf6f7563af46d2 (diff) | |
download | podman-2e35dfa20c60a80ca12ffab68a7fcdac797feb3d.tar.gz podman-2e35dfa20c60a80ca12ffab68a7fcdac797feb3d.tar.bz2 podman-2e35dfa20c60a80ca12ffab68a7fcdac797feb3d.zip |
fix: system df error when an image has no name
When an image has no name/tag system df will
error because it tries to parse an empty name.
This commit makes sure we only parse non
empty names and set the repository and tag
to "<none>" otherwise.
Closes #7015
Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
-rw-r--r-- | pkg/domain/infra/abi/system.go | 19 | ||||
-rw-r--r-- | test/e2e/system_df_test.go | 14 |
2 files changed, 26 insertions, 7 deletions
diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go index 855ca7ff9..be14f52b8 100644 --- a/pkg/domain/infra/abi/system.go +++ b/pkg/domain/infra/abi/system.go @@ -252,13 +252,18 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System } } - named, err := reference.ParseNormalizedNamed(name) - if err != nil { - return nil, err - } - repository = named.Name() - if tagged, isTagged := named.(reference.NamedTagged); isTagged { - tag = tagged.Tag() + if len(name) > 0 { + named, err := reference.ParseNormalizedNamed(name) + if err != nil { + return nil, err + } + repository = named.Name() + if tagged, isTagged := named.(reference.NamedTagged); isTagged { + tag = tagged.Tag() + } + } else { + repository = "<none>" + tag = "<none>" } report := entities.SystemDfImageReport{ diff --git a/test/e2e/system_df_test.go b/test/e2e/system_df_test.go index e882756f9..3d7aaf659 100644 --- a/test/e2e/system_df_test.go +++ b/test/e2e/system_df_test.go @@ -60,4 +60,18 @@ var _ = Describe("podman system df", func() { Expect(containers[1]).To(Equal("2")) Expect(volumes[2]).To(Equal("1")) }) + + It("podman system df image with no tag", func() { + session := podmanTest.PodmanNoCache([]string{"create", ALPINE}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.PodmanNoCache([]string{"image", "untag", ALPINE}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.PodmanNoCache([]string{"system", "df"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) }) |