From 245a338f5a6519f5729749be646abbefd12701d8 Mon Sep 17 00:00:00 2001 From: baude Date: Mon, 8 Jan 2018 14:40:29 -0600 Subject: Add latest to wait It is desirable to have a --latest switch on the podman wait command so we can wait on the latest container created to end. Also, fixes a panic with latest where no containers are available. Signed-off-by: baude Closes: #201 Approved by: baude --- libpod/runtime_ctr.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libpod/runtime_ctr.go') diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 0f39ead35..66dcb2f95 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -271,12 +271,15 @@ func (r *Runtime) GetContainersByList(containers []string) ([]*Container, error) // GetLatestContainer returns a container object of the latest created container. func (r *Runtime) GetLatestContainer() (*Container, error) { - var lastCreatedIndex int + lastCreatedIndex := -1 var lastCreatedTime time.Time ctrs, err := r.GetAllContainers() if err != nil { return nil, errors.Wrapf(err, "unable to find latest container") } + if len(ctrs) == 0 { + return nil, ErrNoSuchCtr + } for containerIndex, ctr := range ctrs { createdTime := ctr.config.CreatedTime if createdTime.After(lastCreatedTime) { -- cgit v1.2.3-54-g00ecf