Merge pull request #742 from jbenet/fix/repo-config-validation

when setting config keys, validate against struct before writing to disk
This commit is contained in:
Brian Tiger Chow 2015-02-03 18:15:02 -08:00
commit 75ffca6b72
4 changed files with 19 additions and 12 deletions

View File

@ -42,7 +42,8 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
Datastore: *ds,
Identity: identity,
Log: Log{
MaxSizeMB: 500,
MaxSizeMB: 250,
MaxBackups: 1,
},
// setup the node mount points.

View File

@ -2,7 +2,7 @@ package config
type Log struct {
MaxSizeMB uint64
MaxBackups uint64
MaxAgeDays uint64
MaxSizeMB int
MaxBackups int
MaxAgeDays int
}

View File

@ -1,6 +1,8 @@
package component
import (
"strconv"
common "github.com/jbenet/go-ipfs/repo/common"
config "github.com/jbenet/go-ipfs/repo/config"
serialize "github.com/jbenet/go-ipfs/repo/fsrepo/serialize"
@ -86,6 +88,12 @@ func (c *ConfigComponent) SetConfigKey(key string, value interface{}) error {
if err != nil {
return err
}
switch v := value.(type) {
case string:
if i, err := strconv.Atoi(v); err == nil {
value = i
}
}
var mapconf map[string]interface{}
if err := serialize.ReadConfigFile(filename, &mapconf); err != nil {
return err
@ -93,15 +101,13 @@ 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
}

View File

@ -38,9 +38,9 @@ var TextFormatter = func() {
type LogRotatorConfig struct {
Filename string
MaxSizeMB uint64
MaxBackups uint64
MaxAgeDays uint64
MaxSizeMB int
MaxBackups int
MaxAgeDays int
}
func Output(w io.Writer) Option {