Add more code for creating/processing diffs
This commit is contained in:
+58
-4
@@ -146,12 +146,40 @@ func (this *config) saveUser () error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *config) processUserDiff (changed []string) {
|
||||
// TODO
|
||||
func (this *config) processUserDiff (changed map[string] struct { }) {
|
||||
for key := range changed {
|
||||
// this is the user file, and nothing has precedence over it, so
|
||||
// the change always matters
|
||||
this.broadcastChange(key)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *config) processSystemDiff (index int, changed []string) {
|
||||
// TODO
|
||||
func (this *config) processSystemDiff (index int, changed map[string] struct { }) {
|
||||
for key := range changed {
|
||||
// if specified in the user file, the change doesn't matter
|
||||
if this.data.user != nil {
|
||||
if has, _ := this.data.user.Has(key); has {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// if specified in any system files with precedence greater than
|
||||
// this one, the change doesn't matter
|
||||
for _, system := range this.data.system[:index] {
|
||||
if _, has := system[key]; has {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// the change does matter
|
||||
this.broadcastChange(key)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *config) broadcastChange (key string) {
|
||||
for _, listener := range this.on.change.Listeners() {
|
||||
listener(key)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *config) get (key string, fallback Value) (Value, error) {
|
||||
@@ -246,3 +274,29 @@ func (this *config) OnChange (callback func (string)) event.Cookie {
|
||||
defer this.lock.Unlock()
|
||||
return this.on.change.Connect(callback)
|
||||
}
|
||||
|
||||
func diffValueMaps (first, second map[string] Value) map[string] struct { } {
|
||||
diff := make(map[string] struct { })
|
||||
|
||||
// - keys only first has
|
||||
// - keys both have, but are different
|
||||
for key, firstValue := range first {
|
||||
secondValue, ok := second[key]
|
||||
if !ok {
|
||||
diff[key] = struct { } { }
|
||||
continue
|
||||
}
|
||||
if !firstValue.Equals(secondValue) {
|
||||
diff[key] = struct { } { }
|
||||
}
|
||||
}
|
||||
|
||||
// - keys only second has
|
||||
for key := range second {
|
||||
if _, has := first[key]; !has {
|
||||
diff[key] = struct { } { }
|
||||
}
|
||||
}
|
||||
|
||||
return diff
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user