Fix timing on database root path initialization

This commit is contained in:
Daniel 2025-02-26 13:23:38 +01:00
parent 4721e58727
commit 130c4a427c
4 changed files with 10 additions and 14 deletions
base/database
dbmodule
main.go
service/core/base

View file

@ -5,7 +5,6 @@ import (
"sync/atomic"
"github.com/safing/portmaster/base/database"
"github.com/safing/portmaster/base/dataroot"
"github.com/safing/portmaster/base/utils"
"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 {
SetDatabaseLocation(dataroot.Root())
if databaseStructureRoot == nil {
return errors.New("database location not specified")
}

View file

@ -9,9 +9,8 @@ import (
"github.com/safing/portmaster/base/utils"
)
const (
databasesSubDir = "databases"
)
// DatabasesSubDir defines the sub directory where the databases are stored.
const DatabasesSubDir = "databases"
var (
initialized = abool.NewBool(false)
@ -34,7 +33,7 @@ func Initialize(dirStructureRoot *utils.DirStructure) error {
rootStructure = dirStructureRoot
// ensure root and databases dirs
databasesStructure = rootStructure.ChildDir(databasesSubDir, utils.AdminOnlyPermission)
databasesStructure = rootStructure.ChildDir(DatabasesSubDir, utils.AdminOnlyPermission)
err := databasesStructure.Ensure()
if err != nil {
return fmt.Errorf("could not create/open database directory (%s): %w", rootStructure.Path, err)

View file

@ -4,8 +4,8 @@ import (
"path/filepath"
"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/dataroot"
"github.com/safing/portmaster/base/utils"
)
@ -17,7 +17,7 @@ var (
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")) {
if utils.PathExists(filepath.Join(dataroot.Root().Path, database.DatabasesSubDir, "core", "bbolt")) {
coreStorageType = "bbolt"
}
@ -33,7 +33,7 @@ func registerDatabases() error {
// If there is an existing cache bbolt database, use it instead.
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"
}

View file

@ -6,6 +6,7 @@ import (
"fmt"
"github.com/safing/portmaster/base/api"
"github.com/safing/portmaster/base/database/dbmodule"
"github.com/safing/portmaster/base/dataroot"
"github.com/safing/portmaster/base/info"
"github.com/safing/portmaster/base/utils"
@ -59,6 +60,9 @@ func prep(instance instance) error {
if err != nil {
return err
}
// Set root dir for the databases.
dbmodule.SetDatabaseLocation(dataroot.Root())
}
// set api listen address