From 2fcb635ac07adf4ff780166ea8357a1327c1b796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20M=C3=ADchal?= Date: Thu, 23 Jul 2020 13:40:08 +0200 Subject: [PATCH] cmd/list: Handle API change of Podman 2.1 in `podman images` Since Podman 2.1 the field 'Created' of `podman images --format json` no longer holds a string with human-readable string in format "5 minutes ago" but holds a Unix time integer[0]. [0] https://github.com/containers/podman/pull/6815 --- src/cmd/list.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cmd/list.go b/src/cmd/list.go index c2e8c6417..5ac3e7f36 100644 --- a/src/cmd/list.go +++ b/src/cmd/list.go @@ -303,7 +303,7 @@ func (i *toolboxImage) UnmarshalJSON(data []byte) error { var raw struct { ID string Names []string - Created string + Created interface{} } if err := json.Unmarshal(data, &raw); err != nil { @@ -312,7 +312,15 @@ func (i *toolboxImage) UnmarshalJSON(data []byte) error { i.ID = raw.ID i.Names = raw.Names - i.Created = raw.Created + // Until Podman 2.0.x the field 'Created' held a human-readable string in + // format "5 minutes ago". Since Podman 2.1 the field holds an integer with + // Unix time. Go interprets numbers in JSON as float64. + switch value := raw.Created.(type) { + case string: + i.Created = value + case float64: + i.Created = utils.HumanDuration(int64(value)) + } return nil }