mirror of
https://github.com/safing/portmaster
synced 2025-04-22 03:49:09 +00:00
Fix timing on database root path initialization
This commit is contained in:
parent
4721e58727
commit
130c4a427c
4 changed files with 10 additions and 14 deletions
|
@ -5,7 +5,6 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/safing/portmaster/base/database"
|
"github.com/safing/portmaster/base/database"
|
||||||
"github.com/safing/portmaster/base/dataroot"
|
|
||||||
"github.com/safing/portmaster/base/utils"
|
"github.com/safing/portmaster/base/utils"
|
||||||
"github.com/safing/portmaster/service/mgr"
|
"github.com/safing/portmaster/service/mgr"
|
||||||
)
|
)
|
||||||
|
@ -36,13 +35,7 @@ func SetDatabaseLocation(dirStructureRoot *utils.DirStructure) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDatabaseLocation returns the initialized database location.
|
|
||||||
func GetDatabaseLocation() string {
|
|
||||||
return databaseStructureRoot.Path
|
|
||||||
}
|
|
||||||
|
|
||||||
func prep() error {
|
func prep() error {
|
||||||
SetDatabaseLocation(dataroot.Root())
|
|
||||||
if databaseStructureRoot == nil {
|
if databaseStructureRoot == nil {
|
||||||
return errors.New("database location not specified")
|
return errors.New("database location not specified")
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,8 @@ import (
|
||||||
"github.com/safing/portmaster/base/utils"
|
"github.com/safing/portmaster/base/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// DatabasesSubDir defines the sub directory where the databases are stored.
|
||||||
databasesSubDir = "databases"
|
const DatabasesSubDir = "databases"
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
initialized = abool.NewBool(false)
|
initialized = abool.NewBool(false)
|
||||||
|
@ -34,7 +33,7 @@ func Initialize(dirStructureRoot *utils.DirStructure) error {
|
||||||
rootStructure = dirStructureRoot
|
rootStructure = dirStructureRoot
|
||||||
|
|
||||||
// ensure root and databases dirs
|
// ensure root and databases dirs
|
||||||
databasesStructure = rootStructure.ChildDir(databasesSubDir, utils.AdminOnlyPermission)
|
databasesStructure = rootStructure.ChildDir(DatabasesSubDir, utils.AdminOnlyPermission)
|
||||||
err := databasesStructure.Ensure()
|
err := databasesStructure.Ensure()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create/open database directory (%s): %w", rootStructure.Path, err)
|
return fmt.Errorf("could not create/open database directory (%s): %w", rootStructure.Path, err)
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"path/filepath"
|
"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/storage/bbolt"
|
_ "github.com/safing/portmaster/base/database/storage/bbolt"
|
||||||
|
"github.com/safing/portmaster/base/dataroot"
|
||||||
"github.com/safing/portmaster/base/utils"
|
"github.com/safing/portmaster/base/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ var (
|
||||||
func registerDatabases() error {
|
func registerDatabases() error {
|
||||||
// If there is an existing bbolt core database, use it instead.
|
// If there is an existing bbolt core database, use it instead.
|
||||||
coreStorageType := DefaultDatabaseStorageType
|
coreStorageType := DefaultDatabaseStorageType
|
||||||
if utils.PathExists(filepath.Join(dbmodule.GetDatabaseLocation(), "core", "bbolt")) {
|
if utils.PathExists(filepath.Join(dataroot.Root().Path, database.DatabasesSubDir, "core", "bbolt")) {
|
||||||
coreStorageType = "bbolt"
|
coreStorageType = "bbolt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func registerDatabases() error {
|
||||||
|
|
||||||
// If there is an existing cache bbolt database, use it instead.
|
// If there is an existing cache bbolt database, use it instead.
|
||||||
cacheStorageType := DefaultDatabaseStorageType
|
cacheStorageType := DefaultDatabaseStorageType
|
||||||
if utils.PathExists(filepath.Join(dbmodule.GetDatabaseLocation(), "cache", "bbolt")) {
|
if utils.PathExists(filepath.Join(dataroot.Root().Path, database.DatabasesSubDir, "cache", "bbolt")) {
|
||||||
cacheStorageType = "bbolt"
|
cacheStorageType = "bbolt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/safing/portmaster/base/api"
|
"github.com/safing/portmaster/base/api"
|
||||||
|
"github.com/safing/portmaster/base/database/dbmodule"
|
||||||
"github.com/safing/portmaster/base/dataroot"
|
"github.com/safing/portmaster/base/dataroot"
|
||||||
"github.com/safing/portmaster/base/info"
|
"github.com/safing/portmaster/base/info"
|
||||||
"github.com/safing/portmaster/base/utils"
|
"github.com/safing/portmaster/base/utils"
|
||||||
|
@ -59,6 +60,9 @@ func prep(instance instance) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set root dir for the databases.
|
||||||
|
dbmodule.SetDatabaseLocation(dataroot.Root())
|
||||||
}
|
}
|
||||||
|
|
||||||
// set api listen address
|
// set api listen address
|
||||||
|
|
Loading…
Add table
Reference in a new issue