Repository navigation
Description
What is the problem you are having with rclone?
When local file system contains circular symlink,
Ubuntu 18.04 "find 4.7.0" is able to follow POSIX standard to detect infinite loops:
The POSIX standard requires that find detects loops:
The find utility shall detect infinite loops; that is, entering a previously visited directory that is an ancestor of the last file encountered. When it detects an infinite loop, find shall write a diagnostic message to standard error and shall either recover its position in the hierarchy or terminate.
However,
rclone (v1.52.1) sync --copy-links continue recursively following the infinite symlink loop
to copy the folders.
What is your rclone version (output from rclone version)
rclone (v1.52.1)
Which OS you are using and how many bits (eg Windows 7, 64 bit)
Ubuntu 18.04
Which cloud storage system are you using? (eg Google Drive)
Box
The command you were trying to run (eg rclone copy /tmp remote:tmp)
/usr/bin/rclone \
--config /opt/Box/rclone.conf \
mount --daemon \
--allow-other \
--uid=18896 --gid=20 \
--log-file /opt/Box/rick-04/mount.log \
--log-level INFO \
--buffer-size 256M \
--transfers 10 \
--checkers 5 \
--retries 8 \
--retries-sleep 15s \
--checksum \
--no-update-modtime \
rick-04: \
/opt/Box/rick-04/mnt
time rclone sync \
/mnt/NB-MxC/NxS/smartnic_1.3_ea1 /opt/Box/rick-04/mnt/NB-MxC/NxS/smartnic_1.3_ea1 \
--config /opt/Box/rclone.conf \
--log-file /opt/Box/rick-04/rclone_sync.log \
--log-level INFO \
--progress \
--buffer-size 1024M \
--transfers 10 \
--checkers 5 \
--retries 8 \
--retries-sleep 15s \
--tpslimit-burst 3 \
--checksum \
--no-update-modtime \
--copy-links \
--order-by modtime,asc \
A log from the command with the -vv flag (eg output from rclone -vv copy /tmp remote:tmp)
2020/07/02 11:30:18 INFO : 2019/July/19_07_09.13_44_13/build-output/stingray-ps250/smartnic_1.3_ea1_stingray-ps250/qa_path/smartnic_1.3_ea1_stingray-ps250/qa_path/smartnic_1.3_ea1_stingray-ps250/qa_path/smartnic_1.3_ea1_stingray-ps250/qa_path/smartnic_1.3_ea1_stingray-ps250/qa_path/smartnic_1.3_ea1_stingray-ps250/qa_path/smartnic_1.3_ea1_stingray-ps250/qa_path/smartnic_1.3_ea1_stingray-ps250/qa_path/smartnic_1.3_ea1_stingray-ps250/qa_path/smartnic_1.3_ea1_stingray-ps250/qa_path/smartnic_1.3_ea1_stingray-ps250/rpm.tar.gz: Copied (new)
Note:
qa_path (at filer-A) has symlink "smartnic_1.3_ea1_stingray-ps250" (at filer-B).
smartnic_1.3_ea1_stingray-ps250 (at filer-B) has symlink "qa_path" (at filer-A).
This created circular symlink loop
but Linux "find" command is able to avoid the loop.
$find -L 2019/July/19_07_09.13_44_13/build-output/stingray-ps250 -name qa_path -type l
find: File system loop detected; ‘2019/July/19_07_09.13_44_13/build-output/stingray-ps250/smartnic_1.3_ea1_stingray-ps250/qa_path’ is part of the same file system loop as ‘2019/July/19_07_09.13_44_13/build-output/stingray-ps250’.
Activity
ncw commentedon Jul 3, 2020
Rclone would take its lead from rsync here - what does rsync do?
totoroliu commentedon Jul 3, 2020
My test environment setup on Ubuntu 18.04:
$ find /tmp/test/tmp/test/tmp/test/folder-B/tmp/test/folder-B/file-B/tmp/test/folder-B/symlink-to-A/tmp/test/folder-A/tmp/test/folder-A/file-A/tmp/test/folder-A/symlink-to-B$ find -L /tmp/test/tmp/test/tmp/test/folder-B/tmp/test/folder-B/file-B/tmp/test/folder-B/symlink-to-A/tmp/test/folder-B/symlink-to-A/file-Afind: File system loop detected; ‘/tmp/test/folder-B/symlink-to-A/symlink-to-B’ is part of the same file system loop as ‘/tmp/test/folder-B’./tmp/test/folder-A/tmp/test/folder-A/file-A/tmp/test/folder-A/symlink-to-B/tmp/test/folder-A/symlink-to-B/file-Bfind: File system loop detected; ‘/tmp/test/folder-A/symlink-to-B/symlink-to-A’ is part of the same file system loop as ‘/tmp/test/folder-A’.$ rsync -rLKkptgoD --dry-run /tmp/test /tmp/test2rsync: readlink_stat("/tmp/test/folder-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B") failed: Too many levels of symbolic links (40)rsync: readlink_stat("/tmp/test/folder-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A/symlink-to-B/symlink-to-A") failed: Too many levels of symbolic links (40) rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1196) [sender=3.1.2]totoroliu commentedon Jul 3, 2020
Ideally, I don't want to copy extra copies:
eg.
/tmp/test/folder-A/symlink-to-B/But It'd would be ok to copy 1 or 2 loops instead of 40 loops:
eg
/tmp/test/folder-A/symlink-to-B/symlink-to-A//tmp/test/folder-A/symlink-to-B/symlink-to-A/symlink-to-B/ncw commentedon Jul 3, 2020
Nice tests - thank you :-)
I tried re-creating your directory tree.
When I try it with rclone I get quite a similar response to that of rsync
So it looks like they are both stopping at a similar number of symlinks. The error returned is actually ELOOP and it is being returned by the kernel.
So the rclone behaviour isn't an infinite recursion at least on my machine - is that what you see too?
I agree stopping once an infinite recursion has been detected would be desirable rather than waiting for the too many links message.
I guess this would need rclone to keep a note of symlinks that have been traversed. I'm not sure how that fits in with the go standard library though - at the moment I just call
Stat()rather thanLStat()and it does it stuff.totoroliu commentedon Jul 3, 2020
I didn't get a chance to see the return of rclone command.
As my folders are pretty big (around 20Gs for folder-A and folder-B),
my rclone has been running for a month and still transferring files from client side.
I found out the issue only after login to Box to check for newly transferred files.
And from the directory structure,
it looks like infinite loop (as i haven't hit the limit of 40 loops).
Let me know if you have the patched rclone.
I could help to verify the fix.
ncw commentedon Jul 4, 2020
Ah!
I'm trying to think of an algorithm for this
So lets say we have a path we want to check that it has symlink loops
/tmp/test/folder-B/symlink-to-A/symlink-to-BWe only need to check this if (so only for symlinks not all files)
-L/--copy-symlinksis in useWe can then resolve all the parts of the path with
Stat(so we follow symlinks) and check to see if any of them point to the same object (by comparing inode number and file system number). If they do then a recursive symlink has been detected.This algorithm should provide the same results as the find call I think.
How does that sound as an algorithm?
totoroliu commentedon Jul 4, 2020
Yes this looks correct.
I see 'find' source code is doing the similar thing tracking the real path the script has visited (using FTS_DC from FTS:
https://git.savannah.gnu.org/cgit/findutils.git/tree/find/ftsfind.c#n363
else if (ent->fts_info == FTS_DC){issue_loop_warning (ent);...
...
https://git.savannah.gnu.org/cgit/findutils.git/tree/find/ftsfind.c#n211
/* We've detected a file system loop. This is caused by one of* two things:** 1. Option -L is in effect and we've hit a symbolic link that* points to an ancestor. This is harmless. We won't traverse the* symbolic link.** 2. We have hit a real cycle in the directory hierarchy. In this* case, we issue a diagnostic message (POSIX requires this) and we* skip that directory entry.*/static voidissue_loop_warning (FTSENT * ent){if (S_ISLNK(ent->fts_statp->st_mode)){error (0, 0,_("Symbolic link %s is part of a loop in the directory hierarchy; we have already visited the directory to which it points."),safely_quote_err_filename (0, ent->fts_path));}ncw commentedon Jul 4, 2020
Do you want to have a go at fixing this @totoroliu ? I can tell you where to start if you want!
totoroliu commentedon Jul 4, 2020
Can you fix it this time?
I need to spend sometime to learn GO first.
arnwas commentedon Dec 26, 2020
Is this still open? Maybe @ncw would like to tell where to start for all of us? I would give it a try then!
totoroliu commentedon Dec 28, 2020
I believe this is still open (although I haven't tried again lately).
I manually cleanup my symlink at source before running rclone.
But I'd really love to have this bug fixed
ncw commentedon Dec 28, 2020
This is still open. I sketched an algorithm for what needs to be done above if someone would like to have a go!
Cellularhacker commentedon Apr 20, 2024
It is still open, too. It should have a solution to avoid infinite symbolic-link loops.
gnubufferoverflows commentedon Jun 30, 2025
I just ran into this issue when using rclone, someone should fix it.
local: stop --copy-links following symlink loops - fixes #4402
ncw commentedon Sep 21, 2026
I've merged @hsdfat fix this to master now which means it will be in the latest beta in 15-30 minutes and released in v1.76
local: stop --copy-links following symlink loops - fixes rclone#4402