From d1da1d40c218d9953a304f3f599ee274e3919d5e Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 3 Feb 2015 16:52:03 -0800 Subject: [PATCH 1/4] 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. --- repo/fsrepo/component/config.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/repo/fsrepo/component/config.go b/repo/fsrepo/component/config.go index 3e4e0c06d..99cc3da46 100644 --- a/repo/fsrepo/component/config.go +++ b/repo/fsrepo/component/config.go @@ -93,15 +93,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 } From bbc9715d4b005877eb73330d03a56b66c36cdec9 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 3 Feb 2015 17:19:05 -0800 Subject: [PATCH 2/4] fix(config, eventlog) use int. it plays nicely with everyone else --- repo/config/log.go | 6 +++--- thirdparty/eventlog/option.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/repo/config/log.go b/repo/config/log.go index 50e7243d4..abaa5c7cb 100644 --- a/repo/config/log.go +++ b/repo/config/log.go @@ -2,7 +2,7 @@ package config type Log struct { - MaxSizeMB uint64 - MaxBackups uint64 - MaxAgeDays uint64 + MaxSizeMB int + MaxBackups int + MaxAgeDays int } diff --git a/thirdparty/eventlog/option.go b/thirdparty/eventlog/option.go index 9ab80cb4c..d44630afb 100644 --- a/thirdparty/eventlog/option.go +++ b/thirdparty/eventlog/option.go @@ -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 { From bbcbf46ce739d628b7547e9c8052e9384eb2cbbc Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 3 Feb 2015 17:18:15 -0800 Subject: [PATCH 3/4] fix(repo/config) detect strings that represent ints --- repo/fsrepo/component/config.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/repo/fsrepo/component/config.go b/repo/fsrepo/component/config.go index 99cc3da46..912533483 100644 --- a/repo/fsrepo/component/config.go +++ b/repo/fsrepo/component/config.go @@ -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 From faded48945d06124ce441d4d9e4c613226c67364 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 3 Feb 2015 17:13:58 -0800 Subject: [PATCH 4/4] fix(config) use max backups to limit number of backups --- repo/config/init.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/repo/config/init.go b/repo/config/init.go index 737f174f2..0efcf629a 100644 --- a/repo/config/init.go +++ b/repo/config/init.go @@ -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.