mirror of
https://github.com/rclone/rclone
synced 2025-01-03 03:46:24 +01:00
parent
5935cb0a29
commit
ba72e62b41
@ -1340,6 +1340,16 @@ func FileDeleteKey(section, key string) bool {
|
||||
|
||||
var matchEnv = regexp.MustCompile(`^RCLONE_CONFIG_(.*?)_TYPE=.*$`)
|
||||
|
||||
// FileRefresh ensures the latest configFile is loaded from disk
|
||||
func FileRefresh() error {
|
||||
reloadedConfigFile, err := loadConfigFile()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
configFile = reloadedConfigFile
|
||||
return nil
|
||||
}
|
||||
|
||||
// FileSections returns the sections in the config file
|
||||
// including any defined by environment variables.
|
||||
func FileSections() []string {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -292,3 +293,21 @@ func TestMatchProvider(t *testing.T) {
|
||||
assert.Equal(t, test.want, got, what)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileRefresh(t *testing.T) {
|
||||
defer testConfigFile(t, "refresh.conf")()
|
||||
require.NoError(t, CreateRemote("refresh_test", "config_test_remote", rc.Params{
|
||||
"bool": true,
|
||||
}))
|
||||
b, err := ioutil.ReadFile(ConfigPath)
|
||||
assert.NoError(t, err)
|
||||
|
||||
b = bytes.Replace(b, []byte("refresh_test"), []byte("refreshed_test"), 1)
|
||||
err = ioutil.WriteFile(ConfigPath, b, 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NotEqual(t, []string{"refreshed_test"}, configFile.GetSectionList())
|
||||
err = FileRefresh()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []string{"refreshed_test"}, configFile.GetSectionList())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user