mirror of
https://github.com/rclone/rclone.git
synced 2025-12-06 00:03:32 +00:00
config: fixed issues with flags/options set by environment vars.
Some environment variables didn’t behave like their corresponding
command line flags. The affected flags were --stats, --log-level,
--separator, --multi-tread-streams, --rc-addr, --rc-user and --rc-pass.
Example:
RCLONE_STATS='10s'
rclone check remote: remote: --progress
# Expected: rclone check remote: remote: --progress –-stats=10s
# Actual: rclone check remote: remote: --progress
Remote specific options set by environment variables was overruled by
less specific backend options set by environment variables. Example:
RCLONE_DRIVE_USE_TRASH='false'
RCLONE_CONFIG_MYDRIVE_USE_TRASH='true'
rclone deletefile myDrive:my-test-file
# Expected: my-test-file is recoverable in the trash folder
# Actual: my-test-file is permanently deleted (not recoverable)
Backend specific options set by environment variables was overruled by
general backend options set by environment variables. Example:
RCLONE_SKIP_LINKS='true'
RCLONE_LOCAL_SKIP_LINKS='false'
rclone lsd local:
# Expected result: Warnings when symlinks are skipped
# Actual result: No warnings when symlinks are skipped
# That is RCLONE_SKIP_LINKS takes precedence
The above issues have been fixed.
The debug logging (-vv) has been enhanced to show when flags are set by
environment variables.
The documentation has been enhanced with details on the precedence of
configuration options.
See pull request #5341 for more information.
This commit is contained in:
committed by
Nick Craig-Wood
parent
fee0abf513
commit
58c99427b3
@@ -14,7 +14,12 @@ type configEnvVars string
|
||||
|
||||
// Get a config item from the environment variables if possible
|
||||
func (configName configEnvVars) Get(key string) (value string, ok bool) {
|
||||
return os.LookupEnv(ConfigToEnv(string(configName), key))
|
||||
envKey := ConfigToEnv(string(configName), key)
|
||||
value, ok = os.LookupEnv(envKey)
|
||||
if ok {
|
||||
Debugf(nil, "Setting %s=%q for %q from environment variable %s", key, value, configName, envKey)
|
||||
}
|
||||
return value, ok
|
||||
}
|
||||
|
||||
// A configmap.Getter to read from the environment RCLONE_option_name
|
||||
@@ -28,14 +33,19 @@ func (oev optionEnvVars) Get(key string) (value string, ok bool) {
|
||||
if opt == nil {
|
||||
return "", false
|
||||
}
|
||||
// For options with NoPrefix set, check without prefix too
|
||||
if opt.NoPrefix {
|
||||
value, ok = os.LookupEnv(OptionToEnv(key))
|
||||
envKey := OptionToEnv(oev.fsInfo.Prefix + "-" + key)
|
||||
value, ok = os.LookupEnv(envKey)
|
||||
if ok {
|
||||
Debugf(nil, "Setting %s_%s=%q from environment variable %s", oev.fsInfo.Prefix, key, value, envKey)
|
||||
} else if opt.NoPrefix {
|
||||
// For options with NoPrefix set, check without prefix too
|
||||
envKey := OptionToEnv(key)
|
||||
value, ok = os.LookupEnv(envKey)
|
||||
if ok {
|
||||
return value, ok
|
||||
Debugf(nil, "Setting %s=%q for %s from environment variable %s", key, value, oev.fsInfo.Prefix, envKey)
|
||||
}
|
||||
}
|
||||
return os.LookupEnv(OptionToEnv(oev.fsInfo.Prefix + "-" + key))
|
||||
return value, ok
|
||||
}
|
||||
|
||||
// A configmap.Getter to read either the default value or the set
|
||||
|
||||
Reference in New Issue
Block a user