Skip to content

Commit 3d59622

Browse files
author
Brian Tiger Chow
committed
fix(repo/config) validate against struct before writing to disk
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.
1 parent 6c3173d commit 3d59622

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

repo/fsrepo/component/config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ func (c *ConfigComponent) SetConfigKey(key string, value interface{}) error {
9393
if err := common.MapSetKV(mapconf, key, value); err != nil {
9494
return err
9595
}
96-
if err := serialize.WriteConfigFile(filename, mapconf); err != nil {
97-
return err
98-
}
9996
// in order to get the updated values, read updated config from the
10097
// file-system.
10198
conf, err := config.FromMap(mapconf)
10299
if err != nil {
103100
return err
104101
}
102+
if err := serialize.WriteConfigFile(filename, mapconf); err != nil {
103+
return err
104+
}
105105
return c.setConfigUnsynced(conf) // TODO roll this into this method
106106
}
107107

0 commit comments

Comments
 (0)