Roland Koebler
2009-Oct-05 23:47 UTC
--copy-unsafe-links does not work for "double" symlinks
Hi, as documented, if you use rsync with --copy-unsafe-links, and copy a directory with a symlink pointing outside of the copied tree, the referent of the symlink is copied. Now, assume that the directory contains a symlink, which points to a (2nd) directory outside of the copied tree. If this (2nd) directory contains another symlink, which also points outside of the copied tree, rsync unfortunately only copies this symlink and *not* the referent. I don't know if this is a rsync-problem or a symlink-problem. (rsync version 3.0.3 protocol version 30, on Debian Lenny) Example: - host 1 directory-structure ("empty"): drwx------ ./1 - host 2 directory-structure: drwx------ ./2 -rw------- ./2/file lrwxrwxrwx ./2/dir -> ../foo drwx------ ./foo -rw------- ./foo/foofile lrwxrwxrwx ./foo/bar -> ../bar drwx------ ./bar -rw------- ./bar/barfile - mirror host 2 to host 1: $ rsync -av --copy-unsafe-links 2/ 1/ sending incremental file list ./ file dir/ dir/bar -> ../bar/ dir/foofile sent 206 bytes received 60 bytes 532.00 bytes/sec total size is 7 speedup is 0.03 Now, host 1 contains: drwx------ ./1 -rw------- ./1/file drwx------ ./1/dir -rw------- ./1/dir/foofile lrwxrwxrws ./1/dir/bar -> ../bar "file", "dir" and "foofile" are ok; but "bar" is a dangling symlink, and "barfile" was not copied. I would have expected that host 1 would contain: drwx------ ./1 -rw------- ./1/file drwx------ ./1/dir -rw------- ./1/dir/foofile drwx------ ./1/dir/bar/ -rw------- ./1/dir/bar/barfile But this is not the case. Is this a bug, or did I miss something? thanks, Roland
Matt McCutchen
2009-Oct-06 03:59 UTC
--copy-unsafe-links does not work for "double" symlinks
On Tue, 2009-10-06 at 01:47 +0200, Roland Koebler wrote:> as documented, if you use rsync with --copy-unsafe-links, and copy a > directory with a symlink pointing outside of the copied tree, the > referent of the symlink is copied. > > Now, assume that the directory contains a symlink, which points to a > (2nd) directory outside of the copied tree. > If this (2nd) directory contains another symlink, which also points outside > of the copied tree, rsync unfortunately only copies this symlink and *not* > the referent.> Example: > > - host 1 directory-structure ("empty"): > drwx------ ./1 > > - host 2 directory-structure: > drwx------ ./2 > -rw------- ./2/file > lrwxrwxrwx ./2/dir -> ../foo > drwx------ ./foo > -rw------- ./foo/foofile > lrwxrwxrwx ./foo/bar -> ../bar > drwx------ ./bar > -rw------- ./bar/barfile > > - mirror host 2 to host 1: > $ rsync -av --copy-unsafe-links 2/ 1/ > sending incremental file list > ./ > file > dir/ > dir/bar -> ../bar/ > dir/foofile > > sent 206 bytes received 60 bytes 532.00 bytes/sec > total size is 7 speedup is 0.03 > > Now, host 1 contains: > drwx------ ./1 > -rw------- ./1/file > drwx------ ./1/dir > -rw------- ./1/dir/foofile > lrwxrwxrws ./1/dir/bar -> ../bar > "file", "dir" and "foofile" are ok; but "bar" is a dangling symlink, and > "barfile" was not copied.Ah, yes. The problem is that rsync is evaluating the safety of the symlink it sees at "dir/bar" as if "dir" were a real directory, ini which case the symlink would indeed be safe. To fix this, rsync would need to remember the last component of the file-list path that was an unsafe symlink and count only the path components after that point in symlink safety checks. I've made a first attempt at implementing this in the "wip/copy-unsafe-links-double" branch of my rsync repository at: https://mattmccutchen.net/rsync/rsync.git/ -- Matt
Maybe Matching Threads
- Can I do this in a template..?
- --keep-dirlinks --delete erroneously deletes symlinks to directories
- creating a callinst to an external function
- Problem restarting client service ssh in client
- [Bug 13827] New: despite --copy-unsafe-links, rsync does not copy the referent of symlinks that point one level outside the copied tree