It appears that 'rsync --backup' is non-atomic.

The code in question is in backup.c, in make_simple_backup():

 64         if (do_rename(fname, fnamebak) == 0) {
 65             if (verbose > 1) {
 66                 rprintf(FINFO, "backed up %s to %s\n",
 67                     fname, fnamebak);
 68             }
 69             break;
 70         }

This has a race condition because 'fname' will be gone until the
rename() from the temp file happens.  It's a small window, but I've
seen it get tripped.

Is there some deep reason to NOT do

        do_unlink(fnamebak);
        do_link(fname, fnamebak);

instead of the do_rename(), so that fname never disappears, and is
updated atomically?

(This is, of course, not actual code; it requires error checking,
verbosity, and a judgement call on what to do about a backup file that
is not unlink()-able.  I figured I'd ask about the underlying logic
before attempting a patch.)


Thanks --

                                        JD Paul
--
Please use reply-all for most replies to avoid omitting the mailing list.
To unsubscribe or change options: https://lists.samba.org/mailman/listinfo/rsync
Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html

Reply via email to