From dbb4b2c900de31e11c8fe06f0f860ccb1be885d5 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 15 Jul 2018 12:39:11 +0100 Subject: [PATCH] fs/config: don't print errors about --config if supplied - fixes #2397 Before this change if the rclone was running in an environment which couldn't find the HOME directory, it would print a warning about supplying a --config flag even if the user had done so. --- fs/config/config.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/fs/config/config.go b/fs/config/config.go index b3fa43972..ad4d2ea3d 100644 --- a/fs/config/config.go +++ b/fs/config/config.go @@ -152,11 +152,24 @@ func makeConfigPath() string { return homeconf } + // Check to see if user supplied a --config variable or environment + // variable. We can't use pflag for this because it isn't initialised + // yet so we search the command line manually. + _, configSupplied := os.LookupEnv("RCLONE_CONFIG") + for _, item := range os.Args { + if item == "--config" || strings.HasPrefix(item, "--config=") { + configSupplied = true + break + } + } + // Default to ./.rclone.conf (current working directory) - fs.Errorf(nil, "Couldn't find home directory or read HOME or XDG_CONFIG_HOME environment variables.") - fs.Errorf(nil, "Defaulting to storing config in current directory.") - fs.Errorf(nil, "Use --config flag to workaround.") - fs.Errorf(nil, "Error was: %v", err) + if !configSupplied { + fs.Errorf(nil, "Couldn't find home directory or read HOME or XDG_CONFIG_HOME environment variables.") + fs.Errorf(nil, "Defaulting to storing config in current directory.") + fs.Errorf(nil, "Use --config flag to workaround.") + fs.Errorf(nil, "Error was: %v", err) + } return hiddenConfigFileName }