summaryrefslogtreecommitdiff
path: root/libpod/boltdb_state.go
diff options
context:
space:
mode:
authorMatthew Heon <mheon@redhat.com>2018-12-02 13:36:55 -0500
committerMatthew Heon <mheon@redhat.com>2018-12-02 13:38:36 -0500
commit137e0948aed96c3fe6412512e0d138eedf71d499 (patch)
tree24ca836a3fe6eaed4ab04dd568bc16d3b386a7c2 /libpod/boltdb_state.go
parentb0f79ff4df58c12fdfaff5c4a7c6e029cb566459 (diff)
downloadpodman-137e0948aed96c3fe6412512e0d138eedf71d499.tar.gz
podman-137e0948aed96c3fe6412512e0d138eedf71d499.tar.bz2
podman-137e0948aed96c3fe6412512e0d138eedf71d499.zip
Make DB config validation an explicit step
Previously, we implicitly validated runtime configuration against what was stored in the database as part of database init. Make this an explicit step, so we can call it after the database has been initialized. This will allow us to retrieve paths from the database and use them to overwrite our defaults if they differ. Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'libpod/boltdb_state.go')
-rw-r--r--libpod/boltdb_state.go29
1 files changed, 24 insertions, 5 deletions
diff --git a/libpod/boltdb_state.go b/libpod/boltdb_state.go
index 7191b184a..37b309c0d 100644
--- a/libpod/boltdb_state.go
+++ b/libpod/boltdb_state.go
@@ -115,11 +115,6 @@ func NewBoltState(path, lockDir string, runtime *Runtime) (State, error) {
return nil, errors.Wrapf(err, "error creating initial database layout")
}
- // Check runtime configuration
- if err := checkRuntimeConfig(db, runtime); err != nil {
- return nil, err
- }
-
state.valid = true
return state, nil
@@ -243,6 +238,10 @@ func (s *BoltState) Refresh() error {
// GetDBConfig retrieves runtime configuration fields that were created when
// the database was first initialized
func (s *BoltState) GetDBConfig() (*DBConfig, error) {
+ if !s.valid {
+ return nil, ErrDBClosed
+ }
+
cfg := new(DBConfig)
db, err := s.getDBCon()
@@ -282,6 +281,26 @@ func (s *BoltState) GetDBConfig() (*DBConfig, error) {
return cfg, nil
}
+// ValidateDBConfig validates paths in the given runtime against the database
+func (s *BoltState) ValidateDBConfig(runtime *Runtime) error {
+ if !s.valid {
+ return ErrDBClosed
+ }
+
+ db, err := s.getDBCon()
+ if err != nil {
+ return err
+ }
+ defer s.closeDBCon(db)
+
+ // Check runtime configuration
+ if err := checkRuntimeConfig(db, runtime); err != nil {
+ return err
+ }
+
+ return nil
+}
+
// SetNamespace sets the namespace that will be used for container and pod
// retrieval
func (s *BoltState) SetNamespace(ns string) error {