fix(DB): modify new data store checking logic (#5756)

* update new data store check logic

* cleanup
pull/5790/head
Hui 2021-09-29 13:24:26 +13:00 committed by GitHub
parent af98660a55
commit 01529203f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -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.