symbolic links

Dave Dykstra dwd at drdykstra.us
Fri Dec 6 20:40:00 EST 2002


I'm sorry, I completely glossed over the -u and -b in your original
email.  I take back what I said and agree it is a bug.  I can reproduce
what you saw:
    mkdir foo bar
    echo hey >foo/file1
    ln -s file1 foo/file2
    sleep 1
    echo there >bar/file1
    echo guy >bar/file2
    ls -l foo bar
    rsync -aub foo/ bar/
    ls -l foo bar

bar/file2 gets overwritten by the symlink and no bar/file2~ is created.

I looked at the code and the main problem is the place in which the
update_only flag is checked in recv_generator: it is only checked after
the code that's run when the originating side is a directory, symlink,
hard link, or device.  Backups aren't done in any of those cases either.
It's been this way at least since the first generator.c in rsync CVS
and apparently nobody has noticed.

It's not clear off the top of my head what's a good way to re-arrange
the code to handle this case.  I suppose a function call should be made
to check for update_only under each of the cases.  I think the backup
can be fixed by checking for make_backups in the delete_file() function;
currently it's only checked in delete_files() and finish_transfer().

Is anybody interested in writing a patch and testing it?

- Dave


On Thu, Dec 05, 2002 at 08:20:51AM -0600, Dave Dykstra wrote:
> Personally I don't see why see why replacing a file with a symbolic
> link is any more dangerous than replacing it with a different file.
> Doesn't it back up the file if you use the --backup option?  If you use
> the --update option rsync shouldn't replace any file or symlink that is
> newer than the either that is older, will that help?
> 
> - Dave 
> 
> On Wed, Dec 04, 2002 at 09:19:44PM -0800, Peter Sturdza wrote:
> > 
> > I don't see any option that works.  My problem is not
> > how it copies the links; it is that rsync will delete
> > a regular file and replace it with the symlink when
> > the file is newer than the symlink.  The file is
> > always erased with no backup.  This seems wrong.
> > 
> > Basically I use rysnc to keep files on two different
> > computers up to date.  Say I replace a symlink on one
> > computer with a file by the same name (perhaps because
> > I want to make a small change to this file but not
> > change the file that is being referred to by the
> > symlink), then rsync the two computers.  In this case,
> > rsync will always erase the updated file and replace
> > it with the older symlink.  
> > 
> > In general, I still do want to preserve symlinks and
> > use option -l, however it seems dangerous for a
> > symlink to overwrite a regular file without backups or
> > regard to timestamps.
> > 
> > This happens on Linux with rsync version 2.5.5.  
> > 
> > Peter
> > 
> > --- Dave Dykstra <dwd at drdykstra.us> wrote:
> > > That's not a bug, it's a feature.  Note that the -a
> > > option is equivalent
> > > to -rlptgoD; replace it with all but the "l" and
> > > then look through the
> > > different options with the word "link" in it in the
> > > man page and see if
> > > one of them does what you want.
> > > 
> > > - Dave Dykstra
> > 
> > __________________________________________________
> > Do you Yahoo!?
> > Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> > http://mailplus.yahoo.com



More information about the rsync mailing list