diff --git a/fs/config/config.go b/fs/config/config.go index d02bc67ea..0bded3ee2 100644 --- a/fs/config/config.go +++ b/fs/config/config.go @@ -332,6 +332,10 @@ func SetConfigPath(path string) (err error) { // SetData sets new config file storage func SetData(newData Storage) { + // If no config file, use in-memory config (which is the default) + if configPath == "" { + return + } data = newData dataLoaded = false } @@ -371,10 +375,6 @@ var ErrorConfigFileNotFound = errors.New("config file not found") // SaveConfig calling function which saves configuration file. // if SaveConfig returns error trying again after sleep. func SaveConfig() { - if configPath == "" { - fs.Debugf(nil, "Skipping save for memory-only config") - return - } ctx := context.Background() ci := fs.GetConfig(ctx) var err error diff --git a/fs/config/configfile/configfile.go b/fs/config/configfile/configfile.go index 829c4ef37..f1eb79ba6 100644 --- a/fs/config/configfile/configfile.go +++ b/fs/config/configfile/configfile.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "sync" "github.com/Unknwon/goconfig" @@ -224,6 +225,10 @@ func (s *Storage) GetValue(section string, key string) (value string, found bool // SetValue sets the value under key in section func (s *Storage) SetValue(section string, key string, value string) { s.check() + if strings.HasPrefix(section, ":") { + fs.Logf(nil, "Can't save config %q for on the fly backend %q", key, section) + return + } s.gc.SetValue(section, key, value) } diff --git a/fs/configmap.go b/fs/configmap.go index e788771ec..31a7d3fa3 100644 --- a/fs/configmap.go +++ b/fs/configmap.go @@ -4,7 +4,6 @@ package fs import ( "os" - "strings" "github.com/rclone/rclone/fs/config/configmap" ) @@ -70,14 +69,10 @@ type setConfigFile string // Set a config item into the config file func (section setConfigFile) Set(key, value string) { - if strings.HasPrefix(string(section), ":") { - Logf(nil, "Can't save config %q = %q for on the fly backend %q", key, value, section) - return - } - Debugf(nil, "Saving config %q = %q in section %q of the config file", key, value, section) + Debugf(nil, "Saving config %q in section %q of the config file", key, section) err := ConfigFileSet(string(section), key, value) if err != nil { - Errorf(nil, "Failed saving config %q = %q in section %q of the config file: %v", key, value, section, err) + Errorf(nil, "Failed saving config %q in section %q of the config file: %v", key, section, err) } }