unroll setConfigUnsynced
Lucas Molas committed
Mar 15, 2022 at 18:00 UTC
76128272b7fbf431eb3c1daf160cd9921a7a1802
1 file changed
+24
-14
repo/fsrepo/fsrepo.go
+24
-14
@@ -542,8 +542,26 @@ func (r *FSRepo) BackupConfig(prefix string) (string, error) {
542
return orig.Name(), nil
543
}
544
545
-// setConfigUnsynced is for private use.
546
-func (r *FSRepo) setConfigUnsynced(updated *config.Config) error {
545
+// SetConfig updates the FSRepo's config. The user must not modify the config
546
+// object after calling this method.
547
+// FIXME: There is an inherent contradiction with storing non-user-generated
548
+// Go config.Config structures as user-generated JSON nested maps. This is
549
+// evidenced by the issue of `omitempty` property of fields that aren't defined
550
+// by the user and Go still needs to initialize them to its default (which
551
+// is not reflected in the repo's config file, see
552
+// https://github.com/ipfs/go-ipfs/issues/8088 for more details).
553
+// In general we should call this API with a JSON nested maps as argument
554
+// (`map[string]interface{}`). Many calls to this function are forced to
555
+// synthesize the config.Config struct from their available JSON map just to
556
+// satisfy this (causing incompatibilities like the `omitempty` one above).
557
+// We need to comb SetConfig calls and replace them when possible with a
558
+// JSON map variant.
559
+func (r *FSRepo) SetConfig(updated *config.Config) error {
560
+
561
+ // packageLock is held to provide thread-safety.
562
+ packageLock.Lock()
563
+ defer packageLock.Unlock()
564
+
565
configFilename, err := config.Filename(r.path)
566
if err != nil {
567
return err
@@ -569,17 +587,6 @@ func (r *FSRepo) setConfigUnsynced(updated *config.Config) error {
587
return nil
588
}
589
572
-// SetConfig updates the FSRepo's config. The user must not modify the config
573
-// object after calling this method.
574
-func (r *FSRepo) SetConfig(updated *config.Config) error {
575
-
576
- // packageLock is held to provide thread-safety.
577
- packageLock.Lock()
578
- defer packageLock.Unlock()
579
-
580
- return r.setConfigUnsynced(updated)
581
-}
582
-
590
// GetConfigKey retrieves only the value of a particular key.
591
func (r *FSRepo) GetConfigKey(key string) (interface{}, error) {
592
packageLock.Lock()
@@ -643,10 +650,13 @@ func (r *FSRepo) SetConfigKey(key string, value interface{}) error {
650
if err != nil {
651
return err
652
}
653
+ r.config = conf
654
+
655
if err := serialize.WriteConfigFile(filename, mapconf); err != nil {
656
return err
657
}
649
- return r.setConfigUnsynced(conf) // TODO roll this into this method
658
+
659
+ return nil
660
}
661
662
// Datastore returns a repo-owned datastore. If FSRepo is Closed, return value