mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-23 19:37:46 +08:00
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:
commit
75ffca6b72
@ -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.
|
||||
|
||||
@ -2,7 +2,7 @@ package config
|
||||
|
||||
|
||||
type Log struct {
|
||||
MaxSizeMB uint64
|
||||
MaxBackups uint64
|
||||
MaxAgeDays uint64
|
||||
MaxSizeMB int
|
||||
MaxBackups int
|
||||
MaxAgeDays int
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
6
thirdparty/eventlog/option.go
vendored
6
thirdparty/eventlog/option.go
vendored
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user