diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-08-21 12:58:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-21 12:58:55 +0200 |
commit | 11372c4c4d75d731f346c6be06e41bfe9600ce81 (patch) | |
tree | 79a8f85f2f8ac32613ce86db3601b355595cf852 /libpod/boltdb_state.go | |
parent | 84180d99bc808795a1f91747436a42745ddececb (diff) | |
parent | 7fc3c25410bd5ee053473ffd5df2209f41840ec0 (diff) | |
download | podman-11372c4c4d75d731f346c6be06e41bfe9600ce81.tar.gz podman-11372c4c4d75d731f346c6be06e41bfe9600ce81.tar.bz2 podman-11372c4c4d75d731f346c6be06e41bfe9600ce81.zip |
Merge pull request #7363 from mheon/lets_try_this_again
Lets try this again: v2.0.5 backports, round 2
Diffstat (limited to 'libpod/boltdb_state.go')
-rw-r--r-- | libpod/boltdb_state.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/libpod/boltdb_state.go b/libpod/boltdb_state.go index 38881d3e4..4e2630526 100644 --- a/libpod/boltdb_state.go +++ b/libpod/boltdb_state.go @@ -424,6 +424,61 @@ func (s *BoltState) SetNamespace(ns string) error { return nil } +// GetName returns the name associated with a given ID. Since IDs are globally +// unique, it works for both containers and pods. +// Returns ErrNoSuchCtr if the ID does not exist. +func (s *BoltState) GetName(id string) (string, error) { + if id == "" { + return "", define.ErrEmptyID + } + + if !s.valid { + return "", define.ErrDBClosed + } + + idBytes := []byte(id) + + db, err := s.getDBCon() + if err != nil { + return "", err + } + defer s.deferredCloseDBCon(db) + + name := "" + + err = db.View(func(tx *bolt.Tx) error { + idBkt, err := getIDBucket(tx) + if err != nil { + return err + } + + nameBytes := idBkt.Get(idBytes) + if nameBytes == nil { + return define.ErrNoSuchCtr + } + + if s.namespaceBytes != nil { + nsBkt, err := getNSBucket(tx) + if err != nil { + return err + } + + idNs := nsBkt.Get(idBytes) + if !bytes.Equal(idNs, s.namespaceBytes) { + return define.ErrNoSuchCtr + } + } + + name = string(nameBytes) + return nil + }) + if err != nil { + return "", err + } + + return name, nil +} + // Container retrieves a single container from the state by its full ID func (s *BoltState) Container(id string) (*Container, error) { if id == "" { |