diff -ru librsync-0.9.7/buf.c librsync-0.9.7-update-in-place/buf.c --- librsync-0.9.7/buf.c 2004-02-07 15:17:57.000000000 -0800 +++ librsync-0.9.7-update-in-place/buf.c 2011-02-15 17:10:07.177068380 -0800 @@ -183,7 +183,31 @@ assert(present > 0); + /* See if we can skip the write operation. + * This is particularly useful when the destination + * is an LVM/SAN snapshot, and the new-file content is already + * identical to the basis-file. + * + * Define DISABLE_UPDATE_IN_PLACE somewhere + * to disable this patch. + */ +#ifndef DISABLE_UPDATE_IN_PLACE + long offset; + char *inbuf = malloc(present); + assert(inbuf != NULL); + + offset = ftell(f); + result = fread(inbuf, 1, present, f); + if (result != present + || memcmp(inbuf, fb->buf, present) != 0) + { + fseek(f, offset, SEEK_SET); + result = fwrite(fb->buf, 1, present, f); + } + free(inbuf); +#else result = fwrite(fb->buf, 1, present, f); +#endif if (present != result) { rs_error("error draining buf to file: %s", strerror(errno)); diff -ru librsync-0.9.7/rdiff.c librsync-0.9.7-update-in-place/rdiff.c --- librsync-0.9.7/rdiff.c 2004-09-17 14:35:50.000000000 -0700 +++ librsync-0.9.7-update-in-place/rdiff.c 2011-02-15 16:03:26.000000000 -0800 @@ -327,7 +327,7 @@ basis_file = rs_file_open(basis_name, "rb"); delta_file = rs_file_open(poptGetArg(opcon), "rb"); - new_file = rs_file_open(poptGetArg(opcon), "wb"); + new_file = rs_file_open(poptGetArg(opcon), "wb+"); rdiff_no_more_args(opcon);