Replace dataroot module with BinDir and DataDir on instance, adapt modules
This commit is contained in:
@@ -2,11 +2,10 @@ package dbmodule
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -27,18 +26,18 @@ func (dbm *DBModule) Stop() error {
|
||||
return stop()
|
||||
}
|
||||
|
||||
var databaseStructureRoot *utils.DirStructure
|
||||
var databasesRootDir string
|
||||
|
||||
// SetDatabaseLocation sets the location of the database for initialization. Supply either a path or dir structure.
|
||||
func SetDatabaseLocation(dirStructureRoot *utils.DirStructure) {
|
||||
if databaseStructureRoot == nil {
|
||||
databaseStructureRoot = dirStructureRoot
|
||||
func SetDatabaseLocation(dir string) {
|
||||
if databasesRootDir == "" {
|
||||
databasesRootDir = dir
|
||||
}
|
||||
}
|
||||
|
||||
func prep() error {
|
||||
SetDatabaseLocation(dataroot.Root())
|
||||
if databaseStructureRoot == nil {
|
||||
SetDatabaseLocation(filepath.Join(module.instance.DataDir(), "databases"))
|
||||
if databasesRootDir == "" {
|
||||
return errors.New("database location not specified")
|
||||
}
|
||||
|
||||
@@ -64,16 +63,16 @@ func New(instance instance) (*DBModule, error) {
|
||||
return nil, errors.New("only one instance allowed")
|
||||
}
|
||||
|
||||
if err := prep(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m := mgr.New("DBModule")
|
||||
module = &DBModule{
|
||||
mgr: m,
|
||||
instance: instance,
|
||||
}
|
||||
if err := prep(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err := database.Initialize(databaseStructureRoot)
|
||||
err := database.Initialize(databasesRootDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -81,4 +80,6 @@ func New(instance instance) (*DBModule, error) {
|
||||
return module, nil
|
||||
}
|
||||
|
||||
type instance interface{}
|
||||
type instance interface {
|
||||
DataDir() string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user