mirror of
https://github.com/safing/portmaster
synced 2025-09-02 18:49:14 +00:00
Add support for database subscription to layered profile provider
This commit is contained in:
parent
079128f9de
commit
607d77a607
2 changed files with 20 additions and 4 deletions
|
@ -14,16 +14,24 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errProfileNotActive = errors.New("profile not active")
|
errProfileNotActive = errors.New("profile not active")
|
||||||
errNoLayeredProfile = errors.New("profile has no layered profile")
|
errNoLayeredProfile = errors.New("profile has no layered profile")
|
||||||
|
pushLayeredProfile runtime.PushFunc = func(...record.Record) {}
|
||||||
)
|
)
|
||||||
|
|
||||||
func registerRevisionProvider() error {
|
func registerRevisionProvider() error {
|
||||||
_, err := runtime.Register(
|
push, err := runtime.Register(
|
||||||
revisionProviderPrefix,
|
revisionProviderPrefix,
|
||||||
runtime.SimpleValueGetterFunc(getRevisions),
|
runtime.SimpleValueGetterFunc(getRevisions),
|
||||||
)
|
)
|
||||||
return err
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pushLayeredProfile = push
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRevisions(key string) ([]record.Record, error) {
|
func getRevisions(key string) ([]record.Record, error) {
|
||||||
|
|
|
@ -127,6 +127,12 @@ func NewLayeredProfile(localProfile *Profile) *LayeredProfile {
|
||||||
new.CreateMeta()
|
new.CreateMeta()
|
||||||
new.SetKey(runtime.DefaultRegistry.DatabaseName() + ":" + revisionProviderPrefix + localProfile.ID)
|
new.SetKey(runtime.DefaultRegistry.DatabaseName() + ":" + revisionProviderPrefix + localProfile.ID)
|
||||||
|
|
||||||
|
// Inform database subscribers about the new layered profile.
|
||||||
|
new.Lock()
|
||||||
|
defer new.Unlock()
|
||||||
|
|
||||||
|
pushLayeredProfile(new)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,6 +237,8 @@ func (lp *LayeredProfile) Update() (revisionCounter uint64) {
|
||||||
|
|
||||||
// bump revision counter
|
// bump revision counter
|
||||||
lp.RevisionCounter++
|
lp.RevisionCounter++
|
||||||
|
|
||||||
|
pushLayeredProfile(lp)
|
||||||
}
|
}
|
||||||
|
|
||||||
return lp.RevisionCounter
|
return lp.RevisionCounter
|
||||||
|
|
Loading…
Add table
Reference in a new issue