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

crstml at libero.it crstml at libero.it
Sun Nov 28 20:20:17 UTC 2021

Hello all

I have a problem with the --copy-unsafe-links option. My environment is
presented and the end of the message. I have the following directory
structure (I hope the that it will be visible; commands below)

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

The directory structure can be created with the following commands:

mkdir -p TST/outside1 TST/tree
echo "outside1" > TST/outside1/outside1-file.txt
echo "outside2" > TST/outside2-file.txt
echo "inside"  > TST/tree/inside.txt
(cd TST/tree/; ln -s ../outside1 ./o1-folder; ln -s ../outside1/outside1-file.txt ./o1-file.txt;)
(cd TST/tree/; ln -s ../outside2-file.txt ./o2-file.txt;)
(cd TST/tree/; ln -s ../../ans.txt ./lnk-ans.txt)

Now if I execute the commands

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

   sending incremental file list
   copying unsafe symlink "tree/lnk-ans.txt" -> "../../ans.txt"
   created directory XXX
   tree/o1-file.txt -> ../outside1/outside1-file.txt
   tree/o1-folder -> ../outside1
   tree/o2-file.txt -> ../outside2-file.txt

   sent 440 bytes  received 93 bytes  1,066.00 bytes/sec
   total size is 147  speedup is 0.28

As we can see from the output rsync makes a copy of tree/lnk-ans.txt
According to the documentation this is correct. --copy-unsafe-links
instructs rsync to make copies of the files outside the copied tree.

But the same should happen for


because all these symlinks point outside tree.

am I missing something? Is this the intended behavior? According to
the documentation (man rsync) I think it is not.

Thank you very much.

-------- BEGIN ENVIRONMNENT ---------

$ rsync --version
rsync  version 3.1.3  protocol version 31
Copyright (C) 1996-2018 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
     64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
     socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
     append, ACLs, xattrs, iconv, symtimes, prealloc
Operating System: Debian 10

-------- END ENVIRONMNENT ---------

More information about the rsync mailing list