Config impl now diffs files and broadcasts events

This commit is contained in:
Sasha Koshka 2024-08-22 19:50:35 -04:00
parent 1f5cb683fb
commit a952490188

View File

@ -6,6 +6,7 @@ import "sync"
import "slices"
import "path/filepath"
import "github.com/fsnotify/fsnotify"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/event"
// Goroutine model:
@ -67,15 +68,19 @@ func (this *config) lockAndProcessEvent (event fsnotify.Event) {
if _, ok := this.paths.watching[event.Name]; !ok { return }
if event.Name == this.paths.user {
previousUser := this.data.user
this.reloadUser()
newUser := this.data.user
this.processUserDiff(newUser.Diff(previousUser))
} else {
index := slices.Index(this.paths.system, event.Name)
if index > 0 {
previousSystem := this.data.system[index]
this.reloadSystem(index)
newSystem := this.data.system[index]
this.processSystemDiff(index, diffValueMaps(newSystem, previousSystem))
}
}
// TODO diff and call event handler if changed
}
func (this *config) init () error {
@ -178,7 +183,7 @@ func (this *config) processSystemDiff (index int, changed map[string] struct { }
func (this *config) broadcastChange (key string) {
for _, listener := range this.on.change.Listeners() {
listener(key)
tomo.Do(func () { listener(key) })
}
}