On Thu, Oct 05, 2000 at 07:47:50PM +0200, Poul-Henning Kamp wrote:
> 
> Hi,
> 
> I found a bug in rsync 2.4.6 + rsync-246-v6-20000907.diff.gz:
> 
> The following tiny script demonstrates a bug in the --copy-unsafe-links
> code:  If the destination of the symbolic link doesn't exist on the
> source system, it is not copied across to the destination system:
> 
>       #!/bin/sh
>       rm -rf s d
>       mkdir s
>       ln -s /foo/glaf/glam s/a
>       touch s/e
>       ln -s e s/f
>       mkdir d
>       rsync -rv  \
>               -l \
>               --copy-unsafe-links \
>               s/. ./d
>       echo "----S"
>       find s -ls
>       echo "----D"
>       find d -ls
> 
> Running it yields this result:
> 
>       building file list ... readlink a: No such file or directory
>       done
>       e
>       f -> e
>       wrote 95 bytes  read 36 bytes  262.00 bytes/sec
>       total size is 1  speedup is 0.01
>       ----S
>       drwxrwxr-x  2 phk   phk  512  5 Okt 19:41 s
>       lrwxrwxr-x  1 phk   phk   14  5 Okt 19:41 s/a -> /foo/glaf/glam
>       -rw-rw-r--  1 phk   phk    0  5 Okt 19:41 s/e
>       lrwxrwxr-x  1 phk   phk    1  5 Okt 19:41 s/f -> e
>       ----D
>       drwxrwxr-x  2 phk   phk  512  5 Okt 19:41 d
>       -rw-rw-r--  1 phk   phk    0  5 Okt 19:41 d/e
>       lrwxrwxrwx  1 phk   phk    1  5 Okt 19:41 d/f -> e
> 
> Apply this patch:
> 
> --- flist.c.old       Wed Sep  6 04:46:43 2000
> +++ flist.c   Thu Oct  5 19:32:22 2000
> @@ -154,7 +154,7 @@
>                       return -1;
>               }
>               Linkbuf[l] = 0;
> -             if (copy_unsafe_links && (topsrcname[0] != '\0') &&
> +             if (!copy_unsafe_links && (topsrcname[0] != '\0') &&
>                                   unsafe_symlink(Linkbuf, topsrcname)) {
>                       return do_stat(Path, Buffer);
>               }
> 
> And the result looks better:
> 
>       building file list ... done
>       a -> /foo/glaf/glam
>       e
>       f -> e
>       wrote 124 bytes  read 36 bytes  320.00 bytes/sec
>       total size is 15  speedup is 0.09
>       ----S
>       drwxrwxr-x  2 phk   phk  512  5 Okt 19:43 s
>       lrwxrwxr-x  1 phk   phk   14  5 Okt 19:43 s/a -> /foo/glaf/glam
>       -rw-rw-r--  1 phk   phk    0  5 Okt 19:43 s/e
>       lrwxrwxr-x  1 phk   phk    1  5 Okt 19:43 s/f -> e
>       ----D
>       drwxrwxr-x  2 phk   phk  512  5 Okt 19:43 d
>       lrwxrwxrwx  1 phk   phk   14  5 Okt 19:43 d/a -> /foo/glaf/glam
>       -rw-rw-r--  1 phk   phk    0  5 Okt 19:43 d/e
>       lrwxrwxrwx  1 phk   phk    1  5 Okt 19:43 d/f -> e
> 
> --
> Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
> [EMAIL PROTECTED]         | TCP/IP since RFC 956
> FreeBSD coreteam member | BSD since 4.3-tahoe
> Never attribute to malice what can adequately be explained by incompetence.
> 


You are misunderstanding what the meaning of --copy-unsafe-links is.  From
the man page:
              This tells rsync to treat symbolic links that point
              outside the source tree like ordinary files.  Abso-
              lute symlinks are also treated like ordinary files,
              and so are any symlinks in the source  path  itself
              when --relative is used.

To treat a file like an ordinary file means to copy it in on the
destination, not treat it like a link.  So if a symlink points nowhere,
rsync has to ignore it or print an error, and it chooses to ignore it.

- Dave Dykstra

Reply via email to