Skip to content

rclone sync --copy-links: infinite symlink loop #4402

Closed

Description

@totoroliu

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

  1. ncw commented on Jul 3, 2020

    @ncw
    Member

    Rclone would take its lead from rsync here - what does rsync do?

  2. added this to the Known Problem milestone on Jul 3, 2020
  3. totoroliu commented on Jul 3, 2020

    @totoroliu
    Author

    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-A
    find: 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-B
    find: 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/test2
    rsync: 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]

  4. totoroliu commented on Jul 3, 2020

    @totoroliu
    Author

    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/

  5. ncw commented on Jul 3, 2020

    @ncw
    Member

    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

    $ rsync -vaL . | wc -l
    rsync: 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(1207) [sender=3.1.3]
    169
    
    $ rclone lsf -LR . | wc -l
    2020/07/03 21:03:41 ERROR : 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: error listing: 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: too many levels of symbolic links
    2020/07/03 21:03:41 ERROR : 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: error listing: 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: too many levels of symbolic links
    2020/07/03 21:03:41 Failed to lsf with 3 errors: last error was: error in ListJSON: 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: too many levels of symbolic links
    162
    

    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.

    newfstatat(AT_FDCWD, "/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", 0xc0007e1ca8, 0) = -1 ELOOP (Too many levels of symbolic links)

    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 than LStat() and it does it stuff.

  6. totoroliu commented on Jul 3, 2020

    @totoroliu
    Author

    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.

  7. ncw commented on Jul 4, 2020

    @ncw
    Member

    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.

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

    We only need to check this if (so only for symlinks not all files)

    • -L/--copy-symlinks is in use
    • Lstat("/tmp/test/folder-B/symlink-to-A/symlink-to-B") is a symlink

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

    • /tmp/test/folder-B/symlink-to-A/symlink-to-B
    • /tmp/test/folder-B/symlink-to-A
    • /tmp/test/folder-B
    • /tmp/test
    • /tmp
    • /

    How does that sound as an algorithm?

  8. totoroliu commented on Jul 4, 2020

    @totoroliu
    Author

    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 void
    issue_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));
    }

  9. ncw commented on Jul 4, 2020

    @ncw
    Member

    Do you want to have a go at fixing this @totoroliu ? I can tell you where to start if you want!

  10. totoroliu commented on Jul 4, 2020

    @totoroliu
    Author

    Can you fix it this time?
    I need to spend sometime to learn GO first.

  11. arnwas commented on Dec 26, 2020

    @arnwas

    Is this still open? Maybe @ncw would like to tell where to start for all of us? I would give it a try then!

  12. totoroliu commented on Dec 28, 2020

    @totoroliu
    Author

    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

  13. ncw commented on Dec 28, 2020

    @ncw
    Member

    This is still open. I sketched an algorithm for what needs to be done above if someone would like to have a go!

  14. Cellularhacker commented on Apr 20, 2024

    @Cellularhacker

    It is still open, too. It should have a solution to avoid infinite symbolic-link loops.

  15. gnubufferoverflows commented on Jun 30, 2025

    @gnubufferoverflows

    I just ran into this issue when using rclone, someone should fix it.

  16. added a commit that references this issue on Sep 21, 2026
    b6beea4
  17. ncw commented on Sep 21, 2026

    @ncw
    Member

    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

  18. added a commit that references this issue on Oct 6, 2026
    fce1a6e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions