From 01529203f1b9a2cc173409ebb6191cc39bf835ad Mon Sep 17 00:00:00 2001 From: Hui Date: Wed, 29 Sep 2021 13:24:26 +1300 Subject: [PATCH] fix(DB): modify new data store checking logic (#5756) * update new data store check logic * cleanup --- api/bolt/datastore.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/api/bolt/datastore.go b/api/bolt/datastore.go index ecc4da880..f729e84b0 100644 --- a/api/bolt/datastore.go +++ b/api/bolt/datastore.go @@ -99,15 +99,10 @@ func NewStore(storePath string, fileService portainer.FileService) (*Store, erro } databasePath := path.Join(storePath, databaseFileName) - databaseFileExists, err := fileService.FileExists(databasePath) - if err != nil { + if _, err := fileService.FileExists(databasePath); err != nil { return nil, err } - if databaseFileExists { - store.isNew = false - } - return store, nil } @@ -120,7 +115,18 @@ func (store *Store) Open() error { } store.connection.DB = db - return store.initServices() + err = store.initServices() + if err != nil { + return err + } + + //if failed to retrieve DBVersion from database + //treat it as a new store + if _, err := store.VersionService.DBVersion(); err != nil { + store.isNew = true + } + + return nil } // Close closes the BoltDB database.