diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-08-10 12:59:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-10 12:59:06 -0400 |
commit | 68fd9aa2cf67a749258ccdc6fa8fd89c2557ebfc (patch) | |
tree | c3b6d5d3f767326407e80f54324acb45daa0fa45 /libpod/in_memory_state.go | |
parent | 5ba21849a517659203a5879553f5dfb20963b7b5 (diff) | |
parent | 569854d6348e1cd74e8d654c88720e5517898f1a (diff) | |
download | podman-68fd9aa2cf67a749258ccdc6fa8fd89c2557ebfc.tar.gz podman-68fd9aa2cf67a749258ccdc6fa8fd89c2557ebfc.tar.bz2 podman-68fd9aa2cf67a749258ccdc6fa8fd89c2557ebfc.zip |
Merge pull request #7223 from mheon/fix_7214
Unconditionally retrieve pod names via API
Diffstat (limited to 'libpod/in_memory_state.go')
-rw-r--r-- | libpod/in_memory_state.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libpod/in_memory_state.go b/libpod/in_memory_state.go index 2ac05e88d..0de25a6ef 100644 --- a/libpod/in_memory_state.go +++ b/libpod/in_memory_state.go @@ -106,6 +106,36 @@ func (s *InMemoryState) SetNamespace(ns string) error { return nil } +// GetName retrieves the name associated with a given ID. +// Works with both Container and Pod IDs. +func (s *InMemoryState) GetName(id string) (string, error) { + if id == "" { + return "", define.ErrEmptyID + } + + var idIndex *truncindex.TruncIndex + if s.namespace != "" { + nsIndex, ok := s.namespaceIndexes[s.namespace] + if !ok { + // We have no containers in the namespace + // Return false + return "", define.ErrNoSuchCtr + } + idIndex = nsIndex.idIndex + } else { + idIndex = s.idIndex + } + + fullID, err := idIndex.Get(id) + if err != nil { + if err == truncindex.ErrNotExist { + return "", define.ErrNoSuchCtr + } + return "", errors.Wrapf(err, "error performing truncindex lookup for ID %s", id) + } + return fullID, nil +} + // Container retrieves a container from its full ID func (s *InMemoryState) Container(id string) (*Container, error) { if id == "" { |