Olaf Faaland [[EMAIL PROTECTED]] writes:

> Towards that end, I need to get rsync to cooperate with a perl
> script.  The perl script may attempt to update a file at the same
> time that rsync is trying to read from it or write to it.  Since I
> am the author of the perl script, I am trying to adapt my script to
> rsync rather than the reverse.

I'm curious about the problem description.  Rsync should only be
trying to write to a file if it is synchronizing it with some other
master copy, so if you are saying that might overlap with Perl
writing, isn't there an underlying risk in your system, since you're
saying you have two master file copies?  Rsync isn't really that great
for keeping two files in sync when either can change, at least not
without some sort of extra control over rsync.

If however, you're saying that Perl may be writing to a file that
rsync might also be using as a master to update some other copy, then
it might just be easier not to worry about the locking.  If Perl
happens to make a change while rsync is copying, it should detect that
during the final checksum and re-institute the copy.  Worst case you
just won't be totally up to date until you rsync again.

To your original question though, I'm fairly certain that rsync
doesn't do any locking at all on its output files.  That's because
rsync is writing to a temporary file during the transfer, and just
renames that file on top of the target file as a final step.  In some
cases it will potentially rename the target file out of the way if it
seems to be busy (e.g., a running executable on some systems), but
that's about it.

I think the "locking" support in util.c that you see is just used by
rsync when running as a server to keep track of the maximum number of
connections in a connections file.

You could in theory add your same locking approach to rsync itself
(probably in recv_files() in receiver.c) such that it tried to lock the
target file during the transfer (which would still be to a temporary
file) and skipped that file if the lock failed.

-- David

/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: [EMAIL PROTECTED]  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/

Reply via email to