Greetings, all.
A co-worker has found a problem with using the '--update' option of
rsync, but
happily he was able to fix it. Since I'm the one who's subscribed to
the
rsync mailing list, I'm the one that gets to share it with y'all. ;)
A snippet of his email to our developers describes the problem:
> Subject: rsync fixed: --update bug
> Date: Friday 18 June 2004 19:39
> From: "Bob Nelson" <bnelson@onairusa.com>
[snip]> - It boils down to this:
>
>? 1). When rsync starts, it builds a list of files that need to be
>? ? ? transferred from the source to the target.
>
>? ? ? [...time passes...]
>
>? 2). It then starts replicating each of those files needing to be
>? ? ? updated one by one, a possibly slow process. A temporary file
>? ? ? is used for the replication.
>
>? ? ? [...time passes...]
>
>? 3). It then moves the temporary file to the target name.
>
> The problem arises in each ``[...time passes...]'' span. The target
> file may have become newer than the source.
>
> Prior to the change I made, ``rsync'' never took this eventuality
into
> account.
>
And now his patch. We hope it's helpful:
*** rsync.c.orig Tue Mar 23 10:16:15 2004
--- rsync.c Fri Jun 18 19:51:37 2004
***************
*** 33,38 ****
--- 33,39 ----
extern int preserve_gid;
extern int preserve_perms;
extern int make_backups;
+ extern int update_only;
/*
***************
*** 235,241 ****
--- 236,261 ----
if (make_backups && !make_backup(fname))
return;
+ /* if the target has been modified since the file list was generated,
+ just delete the tmp file, leaving the target behind. */
+
+ if(update_only) {
+ STRUCT_STAT target_st;
+
+ ret = do_stat(fname, &target_st);
+
+ if(ret == 0) {
+ if(cmp_modtime(target_st.st_mtime, file->modtime) > 0) {
+ rprintf(FINFO, "target \"%s\" newer, deleting
\"%s\"\n",
+ fname, fnametmp);
+ do_unlink(fnametmp);
+ return;
+ }
+ }
+ }
+
/* move tmp file over real file */
+
ret = robust_rename(fnametmp, fname, file->mode & INITACCESSPERMS);
if (ret < 0) {
rprintf(FERROR, "%s %s -> \"%s\": %s\n",
--
====================================================================On Air
Digital USA http://www.onairusa.com
Dallas, Texas a division of Smarts Broadcast Systems
"All I want is a warm bed and a kind word and unlimited power"
-- Ashleigh Brilliant
=====================================================================