mirror of
https://github.com/safing/portmaster
synced 2025-04-21 11:29:09 +00:00
Switch core and cache databases to use sqlite when bbold db is not present
This commit is contained in:
parent
71016baa49
commit
b7c692878b
2 changed files with 26 additions and 13 deletions
|
@ -35,6 +35,11 @@ func SetDatabaseLocation(dir string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDatabaseLocation returns the initialized database location.
|
||||||
|
func GetDatabaseLocation() string {
|
||||||
|
return databasesRootDir
|
||||||
|
}
|
||||||
|
|
||||||
func prep() error {
|
func prep() error {
|
||||||
SetDatabaseLocation(filepath.Join(module.instance.DataDir(), "databases"))
|
SetDatabaseLocation(filepath.Join(module.instance.DataDir(), "databases"))
|
||||||
if databasesRootDir == "" {
|
if databasesRootDir == "" {
|
||||||
|
|
|
@ -1,43 +1,51 @@
|
||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/safing/portmaster/base/database"
|
"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/database/storage/bbolt"
|
||||||
|
"github.com/safing/portmaster/base/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Default Values (changeable for testing).
|
// Default Values (changeable for testing).
|
||||||
var (
|
var (
|
||||||
DefaultDatabaseStorageType = "bbolt"
|
DefaultDatabaseStorageType = "sqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
func registerDatabases() error {
|
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{
|
_, err := database.Register(&database.Database{
|
||||||
Name: "core",
|
Name: "core",
|
||||||
Description: "Holds core data, such as settings and profiles",
|
Description: "Holds core data, such as settings and profiles",
|
||||||
StorageType: DefaultDatabaseStorageType,
|
StorageType: coreStorageType,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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{
|
_, err = database.Register(&database.Database{
|
||||||
Name: "cache",
|
Name: "cache",
|
||||||
Description: "Cached data, such as Intelligence and DNS Records",
|
Description: "Cached data, such as Intelligence and DNS Records",
|
||||||
StorageType: DefaultDatabaseStorageType,
|
StorageType: cacheStorageType,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// _, err = database.Register(&database.Database{
|
|
||||||
// Name: "history",
|
|
||||||
// Description: "Historic event data",
|
|
||||||
// StorageType: DefaultDatabaseStorageType,
|
|
||||||
// })
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue