Example to hit: func (oev optionEnvVars) Get(key string)

I am debugging/fixing an issue with environment variables (--stats, –separator, --log-level, --multi-thread-streams, --rc-…) :nerd_face:

As part of the fix I have added debug logging to show when flags/parameters are being read from environment variables.

I am now in the process of testing my changes, but there is one Get function that I cannot find out how to reach.

Can somebody help me with a simple example to hit an entry breakpoint in the below function:

and even better two examples; one with NoPrefix and one without.

I guess it is being used in the backend configuration, but have not been able to find the right remote/flag combination.

Thanks in advance!

Those are for config by env vars.

So set RCLONE_LOCAL_LINKS or RCLONE_LINKS would be an example with and without prefix to use the --links from the local backend.

Or more straight forwardly RCLONE_DRIVE_USE_TRASH

Thanks, I hit my breakpoint :sweat_smile:

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 :wink:)

The config precedence is defined here

It appears to be in the order of the docs but I think set to the default is being conflated with not set.

I have a feeling that this was recently introduced - can you try some earlier rclone versions and see if that is the case?

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 :smile:

(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).

rclone lsd myLocal,skip_links:/folder/with/symlinks

That's certainly a valid point!

Sorry, but that doesn’t seem to be the situation. Let me illustrate with a fatal example:

    RCLONE_DRIVE_USE_TRASH='false'
    RCLONE_CONFIG_MYDRIVE_USE_TRASH='true'
    rclone touch myDrive:test-trash
    rclone lsl myDrive: --include "test-trash" 
    rclone deletefile myDrive:test-trash
    rclone lsl myDrive,trashed_only: --include "test-trash"

Result according to the docs: A recoverable file in the trash folder.

Actual result: The file isn’t in the trash folder and cannot be recovered.

The actual behavior corresponds to this:

The various different methods of backend configuration are read in this order and the first one with a value is used.

  • 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).
  • Backend specific environment vars, e.g. RCLONE_DRIVE_USE_TRASH.
  • Config file, e.g. use_trash = false.
  • Default values, e.g. true - these can't be changed.

The additions to the current documentation are marked in italic.
The condition taking precedence in the above example is marked in bold.

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.

Thanks, glad you verified and reached the same result :sweat_smile:

Not quite, then we would be missing the backend specific settings, that are possible in some situations.

An example with SKIP-LINKS would make it easier to see all the possibilities:

  • Parameters in connection strings, e.g. myRemote,skip_links:
  • Flag values as supplied on the command line, e.g. --skip-links
  • Command line flags set by environment vars, e.g. RCLONE_SKIP_LINKS.
  • Remote specific environment vars, e.g. RCLONE_CONFIG_MYREMOTE_SKIP_LINKS (see above).
  • Backend specific environment vars, e.g. RCLONE_LOCAL_SKIP_LINKS.
  • Config file, e.g. skip_links = true.
  • Default values, e.g. false - these can't be changed.

and then we still miss the tough part to describe why

  • RCLONE_DRIVE_USE_TRASH overrides RCLONE_CONFIG_MYDRIVE_USE_TRASH but
  • RCLONE_LOCAL_SKIP_LINKS is overridden by RCLONE_CONFIG_MYLOCAL_SKIP_LINKS

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...

I hate to give up and therefore did some extra analysis...

... and found a safe way to fix all the above environment var issues :sweat_smile:

Well done! Will reply on the PR.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.