diff options
author | baude <bbaude@redhat.com> | 2018-01-08 14:40:29 -0600 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-01-08 22:44:38 +0000 |
commit | 245a338f5a6519f5729749be646abbefd12701d8 (patch) | |
tree | f40a53649ffd2e67beae4036c029a46b0f1d5c66 /libpod | |
parent | da7556de4ad1d89bd97e1f6c5a146eee00e8c040 (diff) | |
download | podman-245a338f5a6519f5729749be646abbefd12701d8.tar.gz podman-245a338f5a6519f5729749be646abbefd12701d8.tar.bz2 podman-245a338f5a6519f5729749be646abbefd12701d8.zip |
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 <bbaude@redhat.com>
Closes: #201
Approved by: baude
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/runtime_ctr.go | 5 |
1 files changed, 4 insertions, 1 deletions
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) { |