In the process I discovered a bug/less intuitive setting precedence.
Here is an example to reproduce the issue:
RCLONE_SKIP_LINKS = true #superseeds the rclone default
RCLONE_LOCAL_SKIP_LINKS = false #intuitively supersedes the above
RCLONE_CONFIG_MYLOCAL_SKIP_LINKS = false #intuitively supersedes both above
rclone lsd myLocal:/folder/with/symlinks -vv
Intuitively expected result: folder listing with symlink warnings
Actual result: folder listing without symlink warnings (RCLONE_SKIP_LINKS has precedence)
The precedence is described here, and it actually doesn’t describe the above situation.
Does the result correspond to your expectation?
Do we aim a clarifying the docs or fixing the code?
(You may now be thinking about using flag.Changed, to differ between flags set by the command line and the environment variables. But this difference is exactly what caused the issues I have just fixed - by making sure that flag.Changed is also being set by environment variables )
I have reproduced the issue in rclone 1.54 (02-Feb-2021) and performed a high level debugging of the configuration flow in the latest master.
The root cause seems to be that unspecific (command line) flags takes precedence over remote and backend specific flags. Here is an example to illustrate the dilemma:
RCLONE_CONFIG_MYLOCAL_SKIP_LINKS = false
rclone lsd myLocal::/folder/with/symlinks --skip-links
# Actual result: Folder list without warnings
That is, the unspecific --skip-links on the command line (or from the environment) takes precedence over the very specific RCLONE_CONFIG_MYLOCAL_SKIP_LINKS.
This actually also corresponds to the sequence in func ConfigMap where flag values get preference over remote and backend specific flags:
My best guess is that the issue has been there for 2-3 years.
A bold guess is that the issue can be fixed by moving the code to add the flag values just after the code to add the remote and backend specific flags.
That change will most likely reveal a bug in the following code, where the (more specific) prefixed flag should be checked before the non-prefixed:
I don’t mind giving it a try, if it sounds reasonable to your
(Please note: The full overview of consequences and need for testing is above my head)
I think this is working as documented - the config flags take precedence over ENV vars.
This is quite a different example to the one above.
I don't want to change the precedence of the command line flags - that is too risky to break people's stuff!
However I note that you can use the connection string syntax to specify config which will work specifically and exactly how you want it (one of the reasons I made it).
I did a little test to verify what you are saying - I patched the drive backend to exit with an error reporting the state of use trash
$ rclone lsf drive:
2021/05/17 15:21:01 Failed to create file system for "drive:": UseTrash=true
$ RCLONE_DRIVE_USE_TRASH='false' rclone lsf drive:
2021/05/17 15:21:25 Failed to create file system for "drive:": UseTrash=false
$ RCLONE_DRIVE_USE_TRASH='false' RCLONE_CONFIG_DRIVE_USE_TRASH='true' rclone lsf drive:
2021/05/17 15:21:39 Failed to create file system for "drive:": UseTrash=false
$ RCLONE_CONFIG_DRIVE_USE_TRASH='true' rclone lsf drive:
2021/05/17 15:21:47 Failed to create file system for "drive:": UseTrash=true
Yes I think you are right - RCLONE_DRIVE_USE_TRASH and RCLONE_CONFIG_MYREMOTE_USE_TRASH should swap places.
This is because RCLONE_DRIVE_USE_TRASH is equivalent to the command line value (in fact it sets the default value for it)
The Parameters in connection strings need to be there too
So I think the correct docs should be
Parameters in connection strings, e.g. myDrive,use_trash:
Flag values as supplied on the command line, e.g. --drive-use-trash.
Command line flags set by environment vars, e.g. RCLONE_DRIVE_USE_TRASH.
Remote specific environment vars, e.g. RCLONE_CONFIG_MYREMOTE_USE_TRASH (see above).
Config file, e.g. use_trash = false.
Default values, e.g. true - these can't be changed.
It makes more sense for them to be as they were documented, but it obviously doesn't work like that! Connection strings are a far more reliable way of doing this sort of thing than RCLONE_CONFIG_MYREMOTE_USE_TRASH so hopefully that will become less common.
Ah... These are for global command line options which were missed in the first instance because their environment variables have two spellings RCLONE_SKIP_LINKS and RCLONE_LOCAL_SKIP_LINKS.
Maybe we should regularize that... Make the config variables read both the variant environment variables at the same time and get rid of this Backend specific environment vars, e.g. RCLONE_LOCAL_SKIP_LINKS. level...