fix: remove pointless config type check
This bug was pointed out in https://github.com/ipfs/go-ipfs/pull/1440#discussion_r33892559 but was ignored for some reason.
Steven Allen committed
Jun 16, 2020 at 14:31 UTC
a37ff1fe2663b31d49d0c6a5c214955520657a11
1 file changed
+2
-37
repo/fsrepo/fsrepo.go
+2
-37
@@ -7,7 +7,6 @@ import (
7
"io/ioutil"
8
"os"
9
"path/filepath"
10
- "strconv"
10
"strings"
11
"sync"
12
@@ -615,6 +614,7 @@ func (r *FSRepo) SetConfigKey(key string, value interface{}) error {
614
if err != nil {
615
return err
616
}
617
+ // Load into a map so we don't end up writing any additional defaults to the config file.
618
var mapconf map[string]interface{}
619
if err := serialize.ReadConfigFile(filename, &mapconf); err != nil {
620
return err
@@ -628,42 +628,7 @@ func (r *FSRepo) SetConfigKey(key string, value interface{}) error {
628
return err
629
}
630
631
- // Get the type of the value associated with the key
632
- oldValue, err := common.MapGetKV(mapconf, key)
633
- ok := true
634
- if err != nil {
635
- // key-value does not exist yet
636
- switch v := value.(type) {
637
- case string:
638
- value, err = strconv.ParseBool(v)
639
- if err != nil {
640
- value, err = strconv.Atoi(v)
641
- if err != nil {
642
- value, err = strconv.ParseFloat(v, 32)
643
- if err != nil {
644
- value = v
645
- }
646
- }
647
- }
648
- default:
649
- }
650
- } else {
651
- switch oldValue.(type) {
652
- case bool:
653
- value, ok = value.(bool)
654
- case int:
655
- value, ok = value.(int)
656
- case float32:
657
- value, ok = value.(float32)
658
- case string:
659
- value, ok = value.(string)
660
- default:
661
- }
662
- if !ok {
663
- return fmt.Errorf("wrong config type, expected %T", oldValue)
664
- }
665
- }
666
-
631
+ // Set the key in the map.
632
if err := common.MapSetKV(mapconf, key, value); err != nil {
633
return err
634
}