I have been using this simple patch enough that I know it works for my purpose, now I submit it here, for comments.
--delete-before-update implies -W, unlinks the destination file just before the new (temporary) file is written. This would be used when writing to a small or near full medium to use the minmum space when writing. In my case, I happen to be writing to compact flash, so since -W turns the block checksum off, I need -c to force a checksum to ensure that byte wise identical files are not rewritten. Tim's comment below concerned me, but looking at the code, -W and -c can sensibly be used together. (correct me if I am wrong) -W turns off the per block checksum. -c turns on whole file checksum. so, the flags that I am using "--delete-before-update -c" make sense. [EMAIL PROTECTED] wrote: > -W and -c are actually kind of opposite effects... -W means never > checksum... if it's different in length or time, send it. > -c means ALWAYS checksum, even if time and length are identical.
diff -ru rsync-2.4.6/options.c rsync-2.4.6-delete-before-update/options.c --- rsync-2.4.6/options.c Tue Sep 5 19:46:43 2000 +++ rsync-2.4.6-delete-before-update/options.c Wed Nov 14 08:13:03 2001 @@ -23,6 +23,7 @@ int make_backups = 0; int whole_file = 0; +int delete_before_update = 0; int copy_links = 0; int preserve_links = 0; int preserve_hard_links = 0; @@ -181,7 +182,7 @@ } enum {OPT_VERSION, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE, - OPT_EXCLUDE_FROM, OPT_DELETE, OPT_DELETE_EXCLUDED, OPT_NUMERIC_IDS, + OPT_EXCLUDE_FROM, OPT_DELETE_BEFORE_UPDATE, OPT_DELETE, OPT_DELETE_EXCLUDED, +OPT_NUMERIC_IDS, OPT_RSYNC_PATH, OPT_FORCE, OPT_TIMEOUT, OPT_DAEMON, OPT_CONFIG, OPT_PORT, OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS, OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST, @@ -197,6 +198,7 @@ {"server", 0, 0, OPT_SERVER}, {"sender", 0, 0, OPT_SENDER}, {"existing", 0, 0, OPT_EXISTING}, + {"delete-before-update", 0, 0, OPT_DELETE_BEFORE_UPDATE}, {"delete", 0, 0, OPT_DELETE}, {"delete-excluded", 0, 0, OPT_DELETE_EXCLUDED}, {"force", 0, 0, OPT_FORCE}, @@ -436,6 +438,11 @@ whole_file=1; break; + case OPT_DELETE_BEFORE_UPDATE: + delete_before_update=1; + whole_file=1; + break; + case 'H': #if SUPPORT_HARD_LINKS preserve_hard_links=1; @@ -706,6 +713,9 @@ args[ac++] = "--suffix"; args[ac++] = backup_suffix; } + + if (delete_before_update) + args[ac++] = "--delete-before-update"; if (delete_mode && !delete_excluded) args[ac++] = "--delete"; diff -ru rsync-2.4.6/receiver.c rsync-2.4.6-delete-before-update/receiver.c --- rsync-2.4.6/receiver.c Thu Mar 30 06:23:03 2000 +++ rsync-2.4.6-delete-before-update/receiver.c Wed Nov 14 08:11:21 2001 @@ -34,6 +34,7 @@ extern char *tmpdir; extern char *compare_dest; extern int make_backups; +extern int delete_before_update; extern char *backup_suffix; static struct delete_list { @@ -394,6 +395,17 @@ presmissions then act as though the remote end sent us the file permissions we already have */ file->mode = st.st_mode; + } + + if(delete_before_update) { + if (fd1 != -1) { + close(fd1); + if(robust_unlink(fname) != 0) { + rprintf(FERROR,"unlink %s : +%s\n",fname,strerror(errno)); + continue; + } + fd1 = -1; + } } if (fd1 != -1 && st.st_size > 0) {