mirror of
https://github.com/safing/portmaster
synced 2025-04-08 13:09:11 +00:00
Switch core and cache databases to use sqlite when bbold db is not present
This commit is contained in:
parent
c742c7dfd1
commit
90ead7d5e5
2 changed files with 26 additions and 13 deletions
|
@ -36,6 +36,11 @@ func SetDatabaseLocation(dirStructureRoot *utils.DirStructure) {
|
|||
}
|
||||
}
|
||||
|
||||
// GetDatabaseLocation returns the initialized database location.
|
||||
func GetDatabaseLocation() string {
|
||||
return databaseStructureRoot.Path
|
||||
}
|
||||
|
||||
func prep() error {
|
||||
SetDatabaseLocation(dataroot.Root())
|
||||
if databaseStructureRoot == nil {
|
||||
|
|
|
@ -1,43 +1,51 @@
|
|||
package base
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/safing/portmaster/base/database"
|
||||
_ "github.com/safing/portmaster/base/database/dbmodule"
|
||||
"github.com/safing/portmaster/base/database/dbmodule"
|
||||
_ "github.com/safing/portmaster/base/database/storage/bbolt"
|
||||
"github.com/safing/portmaster/base/utils"
|
||||
)
|
||||
|
||||
// Default Values (changeable for testing).
|
||||
var (
|
||||
DefaultDatabaseStorageType = "bbolt"
|
||||
DefaultDatabaseStorageType = "sqlite"
|
||||
)
|
||||
|
||||
func registerDatabases() error {
|
||||
// If there is an existing bbolt core database, use it instead.
|
||||
coreStorageType := DefaultDatabaseStorageType
|
||||
if utils.PathExists(filepath.Join(dbmodule.GetDatabaseLocation(), "core", "bbolt")) {
|
||||
coreStorageType = "bbolt"
|
||||
}
|
||||
|
||||
// Register core database.
|
||||
_, err := database.Register(&database.Database{
|
||||
Name: "core",
|
||||
Description: "Holds core data, such as settings and profiles",
|
||||
StorageType: DefaultDatabaseStorageType,
|
||||
StorageType: coreStorageType,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If there is an existing cache bbolt database, use it instead.
|
||||
cacheStorageType := DefaultDatabaseStorageType
|
||||
if utils.PathExists(filepath.Join(dbmodule.GetDatabaseLocation(), "cache", "bbolt")) {
|
||||
cacheStorageType = "bbolt"
|
||||
}
|
||||
|
||||
// Register cache database.
|
||||
_, err = database.Register(&database.Database{
|
||||
Name: "cache",
|
||||
Description: "Cached data, such as Intelligence and DNS Records",
|
||||
StorageType: DefaultDatabaseStorageType,
|
||||
StorageType: cacheStorageType,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// _, err = database.Register(&database.Database{
|
||||
// Name: "history",
|
||||
// Description: "Historic event data",
|
||||
// StorageType: DefaultDatabaseStorageType,
|
||||
// })
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue