diff options
author | Matthew Heon <matthew.heon@pm.me> | 2019-02-14 17:52:49 -0500 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-02-21 10:51:42 -0500 |
commit | a3dbb7a837f0c6fe9e12aec6da3778759632f7d1 (patch) | |
tree | e532adb39652b5fa3d1263880e2587285ae4614e /libpod/boltdb_state.go | |
parent | 7fdd20ae5a1ced1faceab9cb0a6e553343911a0b (diff) | |
download | podman-a3dbb7a837f0c6fe9e12aec6da3778759632f7d1.tar.gz podman-a3dbb7a837f0c6fe9e12aec6da3778759632f7d1.tar.bz2 podman-a3dbb7a837f0c6fe9e12aec6da3778759632f7d1.zip |
Add ability to rewrite pod configs in the database
Necessary for rewriting lock IDs as part of renumber.
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/boltdb_state.go')
-rw-r--r-- | libpod/boltdb_state.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libpod/boltdb_state.go b/libpod/boltdb_state.go index 104ec78e9..6214333b9 100644 --- a/libpod/boltdb_state.go +++ b/libpod/boltdb_state.go @@ -827,6 +827,50 @@ func (s *BoltState) RewriteContainerConfig(ctr *Container, newCfg *ContainerConf return err } +// RewritePodConfig rewrites a pod's configuration. +// WARNING: This function is DANGEROUS. Do not use without reading the full +// comment on this function in state.go. +func (s *BoltState) RewritePodConfig(pod *Pod, newCfg *PodConfig) error { + if !s.valid { + return ErrDBClosed + } + + if !pod.valid { + return ErrPodRemoved + } + + newCfgJSON, err := json.Marshal(newCfg) + if err != nil { + return errors.Wrapf(err, "error marshalling new configuration JSON for container %s", pod.ID()) + } + + db, err := s.getDBCon() + if err != nil { + return err + } + defer s.closeDBCon(db) + + err = db.Update(func(tx *bolt.Tx) error { + podBkt, err := getPodBucket(tx) + if err != nil { + return err + } + + podDB := podBkt.Bucket([]byte(pod.ID())) + if podDB == nil { + pod.valid = false + return errors.Wrapf(ErrNoSuchPod, "no pod with ID %s found in DB", pod.ID()) + } + + if err := podDB.Put(configKey, newCfgJSON); err != nil { + return errors.Wrapf(err, "error updating pod %s config JSON", pod.ID()) + } + + return nil + }) + return err +} + // Pod retrieves a pod given its full ID func (s *BoltState) Pod(id string) (*Pod, error) { if id == "" { |