Work on pm restructure

This commit is contained in:
Daniel
2018-12-03 20:02:03 +01:00
parent 62b1c03edc
commit 8fb21fd900
23 changed files with 487 additions and 326 deletions

View File

@@ -1,12 +1,44 @@
package profile
import "sync"
import (
"sync"
"github.com/Safing/portbase/database"
)
var (
globalProfile *Profile
defaultProfile *Profile
globalProfile *Profile
fallbackProfile *Profile
specialProfileLock sync.RWMutex
)
// FIXME: subscribe to changes and update profiles
func initSpecialProfiles() (err error) {
specialProfileLock.Lock()
defer specialProfileLock.Unlock()
globalProfile, err = getSpecialProfile("global")
if err != nil {
if err != database.ErrNotFound {
return err
}
globalProfile = makeDefaultGlobalProfile()
globalProfile.Save(specialNamespace)
}
fallbackProfile, err = getSpecialProfile("fallback")
if err != nil {
if err != database.ErrNotFound {
return err
}
fallbackProfile = makeDefaultFallbackProfile()
fallbackProfile.Save(specialNamespace)
}
return nil
}
func getSpecialProfile(ID string) (*Profile, error) {
return getProfile(specialNamespace, ID)
}