oauthutil: Reload config file off disk before updating token

This fixes the config file being overwritten when two rclones are running.

Fixes #682
This commit is contained in:
Nick Craig-Wood 2016-12-19 15:04:07 +00:00
parent 473bdad00b
commit 1b2dda8c4c
2 changed files with 45 additions and 7 deletions

View file

@ -99,9 +99,12 @@ func putToken(name string, token *oauth2.Token) error {
tokenString := string(tokenBytes)
old := fs.ConfigFile.MustValue(name, fs.ConfigToken)
if tokenString != old {
fs.ConfigFile.SetValue(name, fs.ConfigToken, tokenString)
fs.SaveConfig()
fs.Debug(name, "Saving new token in config file")
err = fs.ConfigSetValueAndSave(name, fs.ConfigToken, tokenString)
if err != nil {
fs.ErrorLog(nil, "Failed to save new token in config file: %v", err)
} else {
fs.Debug(name, "Saved new token in config file")
}
}
return nil
}