Skip to content

Commit

Permalink
fix(repo/config) validate against struct before writing to disk
Browse files Browse the repository at this point in the history
When setting config keys, the program doesn't know whether the
key-to-be-modified exists on the Config struct. (Perhaps, with
reflection, it is possible to find the field). To allow callers to write
non-existent keys, the program would...

Before:
1) converts the in-memory *Config to a map
2) sets the key on the map, and
3) writes this map to disk.
4) Then, it converts this map back into an in-memory struct.

This commit swaps 3 and 4 so the map can be validated against the struct
before being written to disk. This prevents the bug identified in #740.
  • Loading branch information
Brian Tiger Chow committed Feb 4, 2015
1 parent 6c3173d commit 3d59622
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions repo/fsrepo/component/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ func (c *ConfigComponent) SetConfigKey(key string, value interface{}) error {
if err := common.MapSetKV(mapconf, key, value); err != nil {
return err
}
if err := serialize.WriteConfigFile(filename, mapconf); err != nil {
return err
}
// in order to get the updated values, read updated config from the
// file-system.
conf, err := config.FromMap(mapconf)
if err != nil {
return err
}
if err := serialize.WriteConfigFile(filename, mapconf); err != nil {
return err
}
return c.setConfigUnsynced(conf) // TODO roll this into this method
}

Expand Down

0 comments on commit 3d59622

Please sign in to comment.