--copy-unsafe-links unexpected behavior with unsafe symlinks

crstml at libero.it crstml at libero.it
Mon Jan 3 12:56:54 UTC 2022


Hello Wayne

Thank you very much for trying to help,

I have the following three observations:


1) As recommended, I have searched the manual of rsync in order to try
    to find your interpretation about what is going on but the only relevant
    fact that I was able to find was how rsync defines unsafe links:

      Symbolic links are considered unsafe if  they  are  absolute
      symlinks (start with /), empty, or if they contain enough ".."
      components to ascend from the directory being copied.

    In my case  (I copy and paste below my original example for commodity)

    TST/
    +-- outside1
    |    |
    |    +-- outside1-file.txt
    |
    +-- outside2-file.txt
    |
    +-- tree
         +-- inside.txt
         |
         +-- lnk-ans.txt -> ../../ans.txt
         |
         +-- o1-file.txt -> ../outside1/outside1-file.txt
         |
         +-- o1-folder -> ../outside1
         |
         +-- o2-file.txt -> ../outside2-file.txt

    when I run the commands

        $ cd TST
        $ rsync --copy-unsafe-links -avz --delete tree XXX

    In my opinion

        tree/o1-file.txt
        tree/o1-folder
        tree/o2-file.txt

    contain enough .. to ascend from the directory being copied (which
    is "tree")


2) I've also taken into account your observation that

     In this case, the "tree" directory is a part of the transfer
     inside the top-of-transfer dir (the current directory)

    which seems unusual to me (because in my case the directory being
    copied is "tree" and not the current directory (am I missing something?))
    and started the command rsync command from a another folder:

    $ cd ~/dev
    $ rsync --copy-unsafe-links -avz --delete ~/tmp/TST/tree ~/tmp/XXX

    The result is the same

         ~/tmp/TST/tree/lnk-ans.txt

    is copied as a file


    And

         ~/tmp/TST/tree/o1-file.txt
         ~/tmp/TST/tree/o1-folder
         ~/tmp/TST/tree/o2-file.txt

    are copied as broken symblinks.

3) I don't think that the intended behavior of rsync is to consider safe
    the symlinks that point to files and folders that are located just above
    the directory being copied ("tree" in this case).

    If this would be the intended behavior, then there will not be possibile
    to specify that you want and entire directory to be copied (with copies
    of the files pointed by unsafe links), because independently of what you
    specify in the command line as the source tree to be copied there will
    always be the posibility that the tree contains some symlink that points
    to a file that is outside the subtree but located under the parent that
    contains the tree and this file will not be copied.

Best regards
Cristian


> On Sun, Nov 28, 2021 at 12:53 PM Cristian via rsync <rsync at lists.samba.org>
> wrote:
>
>> $ rsync --copy-unsafe-links -avz --delete tree XXX
>>
> In this case, the "tree" directory is a part of the transfer inside the
> top-of-transfer dir (the current directory). Thus any symlinks that don't
> try to escape the current directory are considered to be OK.  You should
> instead suffix "tree" with a slash and add "tree" to your destination path:
>
> $ rsync --copy-unsafe-links -aivz --delete tree/ host:/old/path/tree/
>
> This is discussed in the man page
> <https://download.samba.org/pub/rsync/rsync.1> (search for "unsafe").
>
> ..wayne..
>




More information about the rsync mailing list