aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-02-17 07:52:42 -0500
committerMatthew Heon <mheon@redhat.com>2021-02-18 10:18:24 -0500
commitaf62cb3ca9ab516627c5fb991d541555f8af13f4 (patch)
tree3e3028bc07149e9d33530cde524c8bceba1d5811 /cmd/podman
parent59d2eac78a2a8e619d9c1c53b065f34f0e19795c (diff)
downloadpodman-af62cb3ca9ab516627c5fb991d541555f8af13f4.tar.gz
podman-af62cb3ca9ab516627c5fb991d541555f8af13f4.tar.bz2
podman-af62cb3ca9ab516627c5fb991d541555f8af13f4.zip
podman ps --format '{{ .Size }}' requires --size option
Podman -s crashes when the user specifies the '{{ .Size }}` format on the podman ps command, without specifying the --size option. This PR will stop the crash and print out a logrus.Error stating that the caller should add the --size option. Fixes: https://github.com/containers/podman/issues/9408 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/ps.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/cmd/podman/containers/ps.go b/cmd/podman/containers/ps.go
index 23baca70f..09921b93d 100644
--- a/cmd/podman/containers/ps.go
+++ b/cmd/podman/containers/ps.go
@@ -22,6 +22,7 @@ import (
"github.com/cri-o/ocicni/pkg/ocicni"
"github.com/docker/go-units"
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -392,6 +393,11 @@ func (l psReporter) Command() string {
// Size returns the rootfs and virtual sizes in human duration in
// and output form (string) suitable for ps
func (l psReporter) Size() string {
+ if l.ListContainer.Size == nil {
+ logrus.Errorf("Size format requires --size option")
+ return ""
+ }
+
virt := units.HumanSizeWithPrecision(float64(l.ListContainer.Size.RootFsSize), 3)
s := units.HumanSizeWithPrecision(float64(l.ListContainer.Size.RwSize), 3)
return fmt.Sprintf("%s (virtual %s)", s, virt)