Inline comments effectively remove filter in `--filter-from`

What is the problem you are having with rclone?

Inline comments in a "--filter-from" file effectively remove the filter on that line (with directories in my hands). As far as I can tell this behavior isn't documented/warned and doesn't throw errors.

This tool is super powerful, by the way. Thanks! This is obviously a super small thing. I think that this behavior should simply be noted in the documentation.

Run the command 'rclone version' and share the full output of the command.

Discovered on...

rclone --version
- os/arch: linux/amd64
- go version: go1.15.5

...and vererified issue persists on...

rclone.current --version
- os/version: ubuntu 23.10 (64 bit)
- os/kernel: 6.5.0-35-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.23.1
- go/linking: static
- go/tags: none

Which cloud storage system are you using? (eg Google Drive)

SFTP, but I suspect this is storage system agnostic.

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone copy -vv --immutable <origin>:<path> <destpath> --filter-from my_filters.txt --transfers 10 --tpslimit 10 --dry-run --log-file=./mylogs.log

My filter-files
comment_filters.txt

## exclude this dir that would otherwise match
- /dir1/** # inline comment removes this exclusion

# include dir2 and dir3
+ /dir**

# exclude everything else (required)
- *

no_coment_fitlers.txt

## exclude this dir that would otherwise match
- /dir1/**

# include dir2 and dir3
+ /dir**

# exclude everything else (required)
- *

The rclone config contents with secrets removed.

[<remote_name>]
type = sftp
host = <hostename>
user = <usr>
pass = <passwd>
md5sum_command = none
sha1sum_command = none
shell_type = unix

A log from the command with the -vv flag

Inline comment -- dir1 is not excluded, oops

2024/10/18 18:18:51 DEBUG : rclone: Version "v1.53.3" starting with parameters ["rclone" "copy" "-vv" "--immutable" "<origin>:<path>" "<destpath>" "-P" "--filter-from" "./test_filters.txt" "--transfers" "10" "--tpslimit" "10" "--dry-run" "--log-file=./inline_comment.log"]
2024/10/18 18:18:51 DEBUG : Using config file from "<path_to>/.config/rclone/rclone.conf"
2024/10/18 18:18:51 INFO  : Starting HTTP transaction limiter: max 10 transactions/s with burst 1
2024/10/18 18:18:51 DEBUG : Creating backend with remote "<origin>:<path>"
2024/10/18 18:18:51 DEBUG : sftp://<usr>@<url>:22//<origin+path>: New connection <ip>:<port>-><otherip>:22 to "SSH-2.0-OpenSSH_7.4"
2024/10/18 18:18:51 DEBUG : Creating backend with remote "<destpath>"
2024/10/18 18:18:51 NOTICE: dir3/file3.txt: Skipped copy as --dry-run is set
2024/10/18 18:18:51 DEBUG : sftp://<usr>@<url>:22//<origin+path>: New connection <ip>:<port>-><otherip>:22 to "SSH-2.0-OpenSSH_7.4"
2024/10/18 18:18:51 DEBUG : sftp://<usr>@<url>:22//<origin+path>: New connection <ip>:<port>-><otherip>:22 to "SSH-2.0-OpenSSH_7.4"
2024/10/18 18:18:51 NOTICE: dir1/file1.txt: Skipped copy as --dry-run is set
2024/10/18 18:18:51 NOTICE: dir2/file2.txt: Skipped copy as --dry-run is set
2024/10/18 18:18:51 DEBUG : Local file system at <destpath>: Waiting for checks to finish
2024/10/18 18:18:51 DEBUG : Local file system at <destpath>: Waiting for transfers to finish
2024/10/18 18:18:51 INFO  : 
Transferred:   	         0 / 0 Bytes, -, 0 Bytes/s, ETA -
Transferred:            3 / 3, 100%
Elapsed time:         0.4s

2024/10/18 18:18:51 DEBUG : 29 go routines active

No inline comment -- dir1 excluded properly

2024/10/18 18:17:41 DEBUG : rclone: Version "v1.53.3" starting with parameters ["rclone" "copy" "-vv" "--immutable" "<origin>:<path>" "<destpath>" "-P" "--filter-from" "./test_filters.txt" "--transfers" "10" "--tpslimit" "10" "--dry-run" "--log-file=./no_inline_comment.log"]
2024/10/18 18:17:41 DEBUG : Using config file from "<path_to>/.config/rclone/rclone.conf"
2024/10/18 18:17:41 INFO  : Starting HTTP transaction limiter: max 10 transactions/s with burst 1
2024/10/18 18:17:41 DEBUG : Creating backend with remote "<origin>:<path>"
2024/10/18 18:17:41 DEBUG : sftp://<usr>@<url>:22//<origin+path>: New connection <ip>:<port>-><otherip>:22 to "SSH-2.0-OpenSSH_7.4"
2024/10/18 18:17:41 DEBUG : Creating backend with remote "<destpath>"
2024/10/18 18:17:41 DEBUG : dir1: Excluded
2024/10/18 18:17:41 NOTICE: dir3/file3.txt: Skipped copy as --dry-run is set
2024/10/18 18:17:41 DEBUG : sftp://<usr>@<url>:22//<origin+path>: New connection <ip>:<port>-><otherip>:22 to "SSH-2.0-OpenSSH_7.4"
2024/10/18 18:17:41 NOTICE: dir2/file2.txt: Skipped copy as --dry-run is set
2024/10/18 18:17:41 DEBUG : Local file system at <destpath>: Waiting for checks to finish
2024/10/18 18:17:41 DEBUG : Local file system at <destpath>: Waiting for transfers to finish
2024/10/18 18:17:41 INFO  : 
Transferred:   	         0 / 0 Bytes, -, 0 Bytes/s, ETA -
Transferred:            2 / 2, 100%
Elapsed time:         0.2s

2024/10/18 18:17:41 DEBUG : 20 go routines active

This is ancient rclone version.

Could you please run the same with the latest rclone?

You say:

but it does not say which rclone version it is... Normally it looks like this:

$ rclone version
rclone v1.68.1
- os/version: darwin 15.0.1 (64 bit)
- os/kernel: 24.0.0 (x86_64)
...

Sure, that was a copy/paste oversight...apologies. Also attaching logs for rclone.current with matching version.

The version:

rclone v1.68.1
- os/version: ubuntu 23.10 (64 bit)
- os/kernel: 6.5.0-35-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.23.1
- go/linking: static
- go/tags: none

Comment Inline Log -- exclusion ignored, dir1/file1.txt will copy

2024/10/18 23:36:06 INFO  : Starting transaction limiter: max 10 transactions/s with burst 1
2024/10/18 23:36:06 DEBUG : rclone: Version "v1.68.1" starting with parameters ["rclone.current" "copy" "-vv" "--immutable" "<origin>:<path>" "<dest>" "-P" "--filter-from" "./comment_filters.txt" "--transfers" "10" "--tpslimit" "10" "--dry-run" "--log-file=./inline_comment.log"]
2024/10/18 23:36:06 DEBUG : Creating backend with remote "<origin>:<path>"
2024/10/18 23:36:06 DEBUG : Using config file from "<pathto>/.config/rclone/rclone.conf"
2024/10/18 23:36:06 DEBUG : sftp://<usr>@<url>:22/<path>"SSH-2.0-OpenSSH_7.4"
2024/10/18 23:36:07 DEBUG : sftp://<usr>@<url>:22/<path>"unix" from config
2024/10/18 23:36:07 DEBUG : sftp://<usr>@<url>:22/<path>"<path>"
2024/10/18 23:36:07 DEBUG : Creating backend with remote "<dest>"
2024/10/18 23:36:07 DEBUG : Added delayed dir = "dir1", newDst=<nil>
2024/10/18 23:36:07 DEBUG : Added delayed dir = "dir2", newDst=<nil>
2024/10/18 23:36:07 DEBUG : Added delayed dir = "dir3", newDst=<nil>
2024/10/18 23:36:07 DEBUG : dir3/file3.txt: Need to transfer - File not found at Destination
2024/10/18 23:36:07 NOTICE: dir3/file3.txt: Skipped copy as --dry-run is set (size 0)
2024/10/18 23:36:07 DEBUG : dir2/file2.txt: Need to transfer - File not found at Destination
2024/10/18 23:36:07 NOTICE: dir2/file2.txt: Skipped copy as --dry-run is set (size 0)
2024/10/18 23:36:07 DEBUG : dir1/file1.txt: Need to transfer - File not found at Destination
2024/10/18 23:36:07 NOTICE: dir1/file1.txt: Skipped copy as --dry-run is set (size 0)
2024/10/18 23:36:07 DEBUG : Local file system at <dest>: Waiting for checks to finish
2024/10/18 23:36:07 DEBUG : Local file system at <dest>: Waiting for transfers to finish
2024/10/18 23:36:07 NOTICE: dir3: Skipped set directory modification time as --dry-run is set
2024/10/18 23:36:07 NOTICE: dir1: Skipped set directory modification time as --dry-run is set
2024/10/18 23:36:07 NOTICE: dir2: Skipped set directory modification time as --dry-run is set
2024/10/18 23:36:07 NOTICE: 
Transferred:   	          0 B / 0 B, -, 0 B/s, ETA -
Transferred:            3 / 3, 100%
Elapsed time:         0.5s

2024/10/18 23:36:07 DEBUG : 14 go routines active
2024/10/18 23:36:07 DEBUG : sftp://<usr>@<url>:22//<path>: Closing 1 unused connections

No Comment Inline Log -- exclusion respected, dir1/file1.txt will not copy

2024/10/18 23:36:07 INFO  : Starting transaction limiter: max 10 transactions/s with burst 1
2024/10/18 23:36:07 DEBUG : rclone: Version "v1.68.1" starting with parameters ["rclone.current" "copy" "-vv" "--immutable" "<origin>:<path>" "<dest>" "-P" "--filter-from" "./no_comment_filters.txt" "--transfers" "10" "--tpslimit" "10" "--dry-run" "--log-file=./no_inline_comment.log"]
2024/10/18 23:36:07 DEBUG : Creating backend with remote "<origin>:<path>"
2024/10/18 23:36:07 DEBUG : Using config file from "<pathto>/.config/rclone/rclone.conf"
2024/10/18 23:36:07 DEBUG : sftp://<usr>@<url>:22/<path>"SSH-2.0-OpenSSH_7.4"
2024/10/18 23:36:07 DEBUG : sftp://<usr>@<url>:22/<path>"unix" from config
2024/10/18 23:36:07 DEBUG : sftp://<usr>@<url>:22/<path>"<path>"
2024/10/18 23:36:07 DEBUG : Creating backend with remote "<dest>""
2024/10/18 23:36:07 DEBUG : dir1: Excluded
2024/10/18 23:36:07 DEBUG : Added delayed dir = "dir2", newDst=<nil>
2024/10/18 23:36:07 DEBUG : Added delayed dir = "dir3", newDst=<nil>
2024/10/18 23:36:07 DEBUG : dir3/file3.txt: Need to transfer - File not found at Destination
2024/10/18 23:36:07 NOTICE: dir3/file3.txt: Skipped copy as --dry-run is set (size 0)
2024/10/18 23:36:07 DEBUG : dir2/file2.txt: Need to transfer - File not found at Destination
2024/10/18 23:36:07 NOTICE: dir2/file2.txt: Skipped copy as --dry-run is set (size 0)
2024/10/18 23:36:07 DEBUG : Local file system at <dest>: Waiting for checks to finish
2024/10/18 23:36:07 DEBUG : Local file system at <dest>: Waiting for transfers to finish
2024/10/18 23:36:07 NOTICE: dir3: Skipped set directory modification time as --dry-run is set
2024/10/18 23:36:07 NOTICE: dir2: Skipped set directory modification time as --dry-run is set
2024/10/18 23:36:07 NOTICE: 
Transferred:   	          0 B / 0 B, -, 0 B/s, ETA -
Transferred:            2 / 2, 100%
Elapsed time:         0.4s

2024/10/18 23:36:07 DEBUG : 14 go routines active
2024/10/18 23:36:07 DEBUG : sftp://<usr>@<url>:22//<path>: Closing 1 unused connections

Thank you. Please understand that investigating issues in many years old rclone version is rather waste of time:)

I can reproduce it too. I think that we do not have to "fix" it but rather only put note in docs.

Would you like to add it? You can edit docs directly on github.

Go to rclone/docs/content/filtering.md at master · rclone/rclone · GitHub and click edit. It will let you create fork add changes and submit PT.

Thanks! I agree.

I've submitted a PR: "docs: recommends avoiding inline comments in a filter-file #8140".

T

1 Like

I would put it a bit stronger. Inline comments are not supported. Full stop:) If present they are treated as part of a filter line.

When I dump used filters then it is apparent:

$ cat ../filter.txt
## exclude this dir that would otherwise match
- /dir1/** #test
# include dir2 and dir3
+ /dir**
# exclude everything else (required)
- *

$ rclone lsd . --filter-from ../filter.txt --dump filters
2024/10/19 07:40:11 NOTICE: Automatically setting -vv as --dump is enabled
--- start filters ---
--- File filter rules ---
- ^dir1/.* #test$
+ ^dir.*$
- (^|/)[^/]*$
--- Directory filter rules ---
- ^dir1/.* #test$
+ ^dir.*/$
+ ^dir.*$
- ^.*$
--- end filters ---

Ok, I've modified the PR with stronger language. All the best, T

1 Like

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