Skip to content

Commit

Permalink
fix: remove pointless config type check
Browse files Browse the repository at this point in the history
This bug was pointed out in
#1440 (comment) but was ignored
for some reason.
  • Loading branch information
Stebalien committed Jun 16, 2020
1 parent c0951e7 commit a37ff1f
Showing 1 changed file with 2 additions and 37 deletions.
39 changes: 2 additions & 37 deletions repo/fsrepo/fsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -615,6 +614,7 @@ func (r *FSRepo) SetConfigKey(key string, value interface{}) error {
if err != nil {
return err
}
// Load into a map so we don't end up writing any additional defaults to the config file.
var mapconf map[string]interface{}
if err := serialize.ReadConfigFile(filename, &mapconf); err != nil {
return err
Expand All @@ -628,42 +628,7 @@ func (r *FSRepo) SetConfigKey(key string, value interface{}) error {
return err
}

// Get the type of the value associated with the key
oldValue, err := common.MapGetKV(mapconf, key)
ok := true
if err != nil {
// key-value does not exist yet
switch v := value.(type) {
case string:
value, err = strconv.ParseBool(v)
if err != nil {
value, err = strconv.Atoi(v)
if err != nil {
value, err = strconv.ParseFloat(v, 32)
if err != nil {
value = v
}
}
}
default:
}
} else {
switch oldValue.(type) {
case bool:
value, ok = value.(bool)
case int:
value, ok = value.(int)
case float32:
value, ok = value.(float32)
case string:
value, ok = value.(string)
default:
}
if !ok {
return fmt.Errorf("wrong config type, expected %T", oldValue)
}
}

// Set the key in the map.
if err := common.MapSetKV(mapconf, key, value); err != nil {
return err
}
Expand Down

0 comments on commit a37ff1f

Please sign in to comment.