--copy-unsafe-links does not work for "double" symlinks
Matt McCutchen
matt at mattmccutchen.net
Mon Oct 5 21:59:30 MDT 2009
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
More information about the rsync
mailing list