From 976a020a2f4814ab32686bd47870ddb45699950a Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Mon, 3 Jun 2019 21:14:32 +0200 Subject: [PATCH] Use rclone.conf from rclone executable directory if already existing --- docs/content/docs.md | 6 +++++- fs/config/config.go | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/content/docs.md b/docs/content/docs.md index f65289032..f6b9aedd2 100644 --- a/docs/content/docs.md +++ b/docs/content/docs.md @@ -452,7 +452,11 @@ Specify the location of the rclone config file. Normally the config file is in your home directory as a file called `.config/rclone/rclone.conf` (or `.rclone.conf` if created with an older version). If `$XDG_CONFIG_HOME` is set it will be at -`$XDG_CONFIG_HOME/rclone/rclone.conf` +`$XDG_CONFIG_HOME/rclone/rclone.conf`. + +If there is a file `rclone.conf` in the same directory as the rclone +executable it will be preferred. This file must be created manually +for Rclone to use it, it will never be created automatically. If you run `rclone config file` you will see where the default location is for you. diff --git a/fs/config/config.go b/fs/config/config.go index c48a2f885..01230f77b 100644 --- a/fs/config/config.go +++ b/fs/config/config.go @@ -105,6 +105,18 @@ func getConfigData() *goconfig.ConfigFile { // Return the path to the configuration file func makeConfigPath() string { + + // Use rclone.conf from rclone executable directory if already existing + exe, err := os.Executable() + if err == nil { + exedir := filepath.Dir(exe) + cfgpath := filepath.Join(exedir, configFileName) + _, err := os.Stat(cfgpath) + if err == nil { + return cfgpath + } + } + // Find user's home directory homeDir, err := homedir.Dir()