summaryrefslogtreecommitdiff
path: root/libpod/boltdb_state.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-08-10 12:59:06 -0400
committerGitHub <noreply@github.com>2020-08-10 12:59:06 -0400
commit68fd9aa2cf67a749258ccdc6fa8fd89c2557ebfc (patch)
treec3b6d5d3f767326407e80f54324acb45daa0fa45 /libpod/boltdb_state.go
parent5ba21849a517659203a5879553f5dfb20963b7b5 (diff)
parent569854d6348e1cd74e8d654c88720e5517898f1a (diff)
downloadpodman-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/boltdb_state.go')
-rw-r--r--libpod/boltdb_state.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/libpod/boltdb_state.go b/libpod/boltdb_state.go
index 2575f0e86..9dd5ca465 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 == "" {