Fixed patch to work with --delete-delay.
[rsync/rsync-patches.git] / detect-renamed.diff
CommitLineData
1fffd582
WD
1This patch adds the --detect-renamed option which makes rsync notice files
2that either (1) match in size & modify-time (plus the basename, if possible)
3or (2) match in size & checksum (when --checksum was also specified) and use
4each match as an alternate basis file to speed up the transfer.
5
6The algorithm attempts to scan the receiving-side's files in an efficient
7manner. If --delete[-before] is enabled, we'll take advantage of the
8pre-transfer delete pass to prepare any alternate-basis-file matches we
9might find. If --delete-before is not enabled, rsync does the rename scan
10during the regular file-sending scan (scanning each directory right before
11the generator starts updating files from that dir). In this latter mode,
12rsync might delay the updating of a file (if no alternate-basis match was
13yet found) until the full scan of the receiving side is complete, at which
14point any delayed files are processed.
15
16I chose to hard-link the alternate-basis files into a ".~tmp~" subdir that
17takes advantage of rsync's pre-existing partial-dir logic. This uses less
18memory than trying to keep track of the matches internally, and also allows
19any deletions or file-updates to occur normally without interfering with
20these alternate-basis discoveries.
21
03019e41 22To use this patch, run these commands for a successful build:
1fffd582 23
03019e41
WD
24 patch -p1 <patches/detect-renamed.diff
25 ./configure (optional if already run)
1fffd582
WD
26 make
27
28TODO:
29
30 We need to never return a match from fattr_find() that has a basis
31 file. This will ensure that we don't try to give a renamed file to
32 a file that can't use it, while missing out on giving it to a file
33 that could use it.
34
35--- old/flist.c
36+++ new/flist.c
70891d26 37@@ -54,6 +54,7 @@ extern int non_perishable_cnt;
1fffd582
WD
38 extern int prune_empty_dirs;
39 extern int copy_links;
40 extern int copy_unsafe_links;
41+extern int detect_renamed;
42 extern int protocol_version;
43 extern int sanitize_paths;
03019e41 44 extern struct stats stats;
81172142 45@@ -77,6 +78,8 @@ static dev_t tmp_rdev;
70891d26
WD
46 static struct idev tmp_idev;
47 static char tmp_sum[MD4_SUM_LENGTH];
1fffd582
WD
48
49+struct file_list the_fattr_list;
50+
51 static char empty_sum[MD4_SUM_LENGTH];
52 static int flist_count_offset;
53
81172142 54@@ -259,6 +262,44 @@ static mode_t from_wire_mode(int mode)
03019e41 55 return mode;
1fffd582
WD
56 }
57
58+static int fattr_compare(struct file_struct **file1, struct file_struct **file2)
59+{
60+ struct file_struct *f1 = *file1;
61+ struct file_struct *f2 = *file2;
62+ int diff;
63+
64+ if (!f1->basename || !S_ISREG(f1->mode) || !f1->length) {
65+ if (!f2->basename || !S_ISREG(f2->mode) || !f2->length)
66+ return 0;
67+ return 1;
68+ }
69+ if (!f2->basename || !S_ISREG(f2->mode) || !f2->length)
70+ return -1;
71+
72+ /* Don't use diff for values that are longer than an int. */
73+ if (f1->length != f2->length)
74+ return f1->length < f2->length ? -1 : 1;
75+
76+ if (always_checksum) {
70891d26 77+ diff = u_memcmp(F_SUM(f1), F_SUM(f2), checksum_len);
1fffd582
WD
78+ if (diff)
79+ return diff;
80+ } else if (f1->modtime != f2->modtime)
81+ return f1->modtime < f2->modtime ? -1 : 1;
82+
83+ diff = u_strcmp(f1->basename, f2->basename);
84+ if (diff)
85+ return diff;
86+
87+ if (f1->dirname == f2->dirname)
88+ return 0;
89+ if (!f1->dirname)
90+ return -1;
91+ if (!f2->dirname)
92+ return 1;
93+ return u_strcmp(f1->dirname, f2->dirname);
94+}
95+
96 static void send_directory(int f, struct file_list *flist,
97 char *fbuf, int len);
98
81172142 99@@ -1411,6 +1452,25 @@ struct file_list *recv_file_list(int f)
1fffd582
WD
100
101 clean_flist(flist, relative_paths, 1);
102
103+ if (detect_renamed) {
104+ int j = flist->count;
105+ the_fattr_list.count = j;
106+ the_fattr_list.files = new_array(struct file_struct *, j);
107+ if (!the_fattr_list.files)
70891d26 108+ out_of_memory("recv_file_list");
1fffd582
WD
109+ memcpy(the_fattr_list.files, flist->files,
110+ j * sizeof (struct file_struct *));
111+ qsort(the_fattr_list.files, j,
112+ sizeof the_fattr_list.files[0], (int (*)())fattr_compare);
113+ the_fattr_list.low = 0;
114+ while (j-- > 0) {
115+ struct file_struct *fp = the_fattr_list.files[j];
116+ if (fp->basename && S_ISREG(fp->mode) && fp->length)
117+ break;
118+ }
119+ the_fattr_list.high = j;
120+ }
121+
122 if (f >= 0) {
123 recv_uid_list(f, flist);
124
125--- old/generator.c
126+++ new/generator.c
81172142 127@@ -76,6 +76,7 @@ extern char *basis_dir[];
1fffd582
WD
128 extern int compare_dest;
129 extern int copy_dest;
130 extern int link_dest;
131+extern int detect_renamed;
132 extern int whole_file;
133 extern int list_only;
03019e41 134 extern int new_root_dir;
81172142 135@@ -91,16 +92,19 @@ extern char *backup_dir;
1fffd582
WD
136 extern char *backup_suffix;
137 extern int backup_suffix_len;
138 extern struct file_list *the_file_list;
139+extern struct file_list the_fattr_list;
140 extern struct filter_list_struct server_filter_list;
141
d16b5fd6
WD
142 int ignore_perishable = 0;
143 int non_perishable_cnt = 0;
144
1fffd582
WD
145 static int deletion_count = 0; /* used to implement --max-delete */
146+static int unexplored_dirs = 1;
f813befd 147 static FILE *delete_delay_fp = NULL;
81172142 148 static BOOL solo_file = 0;
1fffd582 149
d16b5fd6
WD
150-/* For calling delete_item() and delete_dir_contents(). */
151+/* For calling delete_item(), delete_dir_contents(), and delete_in_dir(). */
152+#define DEL_NO_DELETIONS (1<<0)
87d0091c 153 #define DEL_RECURSE (1<<1) /* recurse */
d16b5fd6 154 #define DEL_DIR_IS_EMPTY (1<<2) /* internal delete_FUNCTIONS use only */
1fffd582 155
81172142 156@@ -122,11 +126,121 @@ static int is_backup_file(char *fn)
1fffd582
WD
157 return k > 0 && strcmp(fn+k, backup_suffix) == 0;
158 }
159
160+/* Search for a regular file that matches either (1) the size & modified
161+ * time (plus the basename, if possible) or (2) the size & checksum. If
162+ * we find an exact match down to the dirname, return -1 because we found
163+ * an up-to-date file in the transfer, not a renamed file. */
164+static int fattr_find(struct file_struct *f, char *fname, alloc_pool_t pool)
165+{
166+ int low = the_fattr_list.low, high = the_fattr_list.high;
167+ int mid, ok_match = -1, good_match = -1;
168+ struct file_struct *fmid;
169+ int diff;
170+
171+ while (low <= high) {
172+ mid = (low + high) / 2;
173+ fmid = the_fattr_list.files[mid];
174+ if (fmid->length != f->length) {
175+ if (fmid->length < f->length)
176+ low = mid + 1;
177+ else
178+ high = mid - 1;
179+ continue;
180+ }
181+ if (always_checksum) {
70891d26 182+ if (!F_SUM(f)) {
1fffd582
WD
183+ if (fmid->modtime == f->modtime
184+ && f_name_cmp(fmid, f) == 0)
185+ return -1; /* assume we can't help */
70891d26
WD
186+ /* XXX update this to new checksum var idiom! */
187+ F_SUM(f) = pool_alloc(pool, MD4_SUM_LENGTH,
1fffd582 188+ "fattr_find");
70891d26 189+ file_checksum(fname, F_SUM(f), f->length);
1fffd582 190+ }
70891d26 191+ diff = u_memcmp(F_SUM(fmid), F_SUM(f), checksum_len);
1fffd582
WD
192+ if (diff) {
193+ if (diff < 0)
194+ low = mid + 1;
195+ else
196+ high = mid - 1;
197+ continue;
198+ }
199+ } else {
200+ if (fmid->modtime != f->modtime) {
201+ if (fmid->modtime < f->modtime)
202+ low = mid + 1;
203+ else
204+ high = mid - 1;
205+ continue;
206+ }
207+ }
208+ ok_match = mid;
209+ diff = u_strcmp(fmid->basename, f->basename);
210+ if (diff == 0) {
211+ good_match = mid;
212+ if (fmid->dirname == f->dirname)
213+ return -1; /* file is up-to-date */
214+ if (!fmid->dirname) {
215+ low = mid + 1;
216+ continue;
217+ }
218+ if (!f->dirname) {
219+ high = mid - 1;
220+ continue;
221+ }
222+ diff = u_strcmp(fmid->dirname, f->dirname);
223+ if (diff == 0)
224+ return -1; /* file is up-to-date */
225+ }
226+ if (diff < 0)
227+ low = mid + 1;
228+ else
229+ high = mid - 1;
230+ }
231+
232+ return good_match >= 0 ? good_match : ok_match;
233+}
234+
235+static void look_for_rename(struct file_struct *file, char *fname,
236+ alloc_pool_t pool)
237+{
238+ struct file_struct *fp;
239+ char *partialptr, *fn;
240+ STRUCT_STAT st;
241+ int ndx;
242+
243+ if ((ndx = fattr_find(file, fname, pool)) < 0)
244+ return;
245+
246+ fp = the_fattr_list.files[ndx];
247+ fn = f_name(fp, NULL);
248+ /* We don't provide an alternate-basis file if there is a basis file. */
249+ if (link_stat(fn, &st, 0) == 0)
250+ return;
251+ if ((partialptr = partial_dir_fname(fn)) == NULL
252+ || !handle_partial_dir(partialptr, PDIR_CREATE))
253+ return;
254+
255+ /* We only use the file if we can hard-link it into our tmp dir. */
256+ if (link(fname, partialptr) == 0) {
257+ if (verbose > 2) {
258+ rprintf(FINFO, "found renamed: %s => %s\n",
259+ fname, partialptr);
260+ }
261+ return;
262+ }
263+
264+ if (errno != EEXIST)
265+ handle_partial_dir(partialptr, PDIR_DELETE);
266+}
87d0091c
WD
267+
268 /* Delete a file or directory. If DEL_RECURSE is set in the flags, this will
269 * delete recursively.
1fffd582 270 *
f813befd 271 * Note that fbuf must point to a MAXPATHLEN buffer if the mode indicates it's
15894839
WD
272 * a directory! (The buffer is used for recursion, but returned unchanged.)
273+ *
274+ * Also note: --detect-rename may use this routine with DEL_NO_DELETIONS set!
275 */
f813befd 276 static enum delret delete_item(char *fbuf, int mode, char *replace, int flags)
15894839 277 {
81172142 278@@ -148,6 +262,8 @@ static enum delret delete_item(char *fbu
15894839
WD
279 goto check_ret;
280 /* OK: try to delete the directory. */
281 }
282+ if (flags & DEL_NO_DELETIONS)
283+ return DR_SUCCESS;
284
285 if (!replace && max_delete >= 0 && ++deletion_count > max_delete)
286 return DR_AT_LIMIT;
81172142 287@@ -194,6 +310,8 @@ static enum delret delete_item(char *fbu
d16b5fd6
WD
288 * its contents, otherwise just checks for content. Returns DR_SUCCESS or
289 * DR_NOT_EMPTY. Note that fname must point to a MAXPATHLEN buffer! (The
290 * buffer is used for recursion, but returned unchanged.)
1fffd582 291+ *
87d0091c 292+ * Note: --detect-rename may use this routine with DEL_NO_DELETIONS set!
1fffd582 293 */
87d0091c 294 static enum delret delete_dir_contents(char *fname, int flags)
1fffd582 295 {
81172142 296@@ -250,6 +368,8 @@ static enum delret delete_dir_contents(c
d16b5fd6
WD
297 if (S_ISDIR(fp->mode)
298 && delete_dir_contents(fname, flags | DEL_RECURSE) != DR_SUCCESS)
299 ret = DR_NOT_EMPTY;
300+ if (detect_renamed && S_ISREG(fp->mode))
301+ look_for_rename(fp, fname, dirlist->file_pool);
302 if (delete_item(fname, fp->mode, NULL, flags) != DR_SUCCESS)
303 ret = DR_NOT_EMPTY;
304 }
81172142 305@@ -334,15 +454,19 @@ static void delayed_deletions(char *delb
1fffd582
WD
306 * all the --delete-WHEN options. Note that the fbuf pointer must point to a
307 * MAXPATHLEN buffer with the name of the directory in it (the functions we
308 * call will append names onto the end, but the old dir value will be restored
309- * on exit). */
310+ * on exit).
311+ *
312+ * Note: --detect-rename may use this routine with DEL_NO_DELETIONS set!
313+ */
314 static void delete_in_dir(struct file_list *flist, char *fbuf,
315- struct file_struct *file, STRUCT_STAT *stp)
316+ struct file_struct *file, STRUCT_STAT *stp, int flags)
317 {
318 static int min_depth = MAXPATHLEN, cur_depth = -1;
319 static void *filt_array[MAXPATHLEN/2+1];
320 static int already_warned = 0;
321 struct file_list *dirlist;
322- char delbuf[MAXPATHLEN];
323+ char *p, delbuf[MAXPATHLEN];
324+ unsigned remainder;
325 int dlen, i;
326
327 if (!flist) {
81172142 328@@ -356,6 +480,8 @@ static void delete_in_dir(struct file_li
1fffd582
WD
329 if (verbose > 2)
330 rprintf(FINFO, "delete_in_dir(%s)\n", fbuf);
331
87d0091c 332+ flags |= DEL_RECURSE;
1fffd582
WD
333+
334 if (allowed_lull)
335 maybe_send_keepalive();
336
81172142 337@@ -363,12 +489,14 @@ static void delete_in_dir(struct file_li
1fffd582
WD
338 return; /* Impossible... */
339
340 if (io_error && !(lp_ignore_errors(module_id) || ignore_errors)) {
341- if (already_warned)
342+ if (!already_warned) {
343+ rprintf(FINFO,
344+ "IO error encountered -- skipping file deletion\n");
345+ already_warned = 1;
346+ }
347+ if (!detect_renamed)
348 return;
349- rprintf(FINFO,
350- "IO error encountered -- skipping file deletion\n");
351- already_warned = 1;
352- return;
353+ flags |= DEL_NO_DELETIONS;
354 }
355
356 while (cur_depth >= file->dir.depth && cur_depth >= min_depth)
81172142 357@@ -379,6 +507,9 @@ static void delete_in_dir(struct file_li
1fffd582
WD
358 dlen = strlen(fbuf);
359 filt_array[cur_depth] = push_local_filters(fbuf, dlen);
360
361+ if (detect_renamed)
362+ unexplored_dirs--;
363+
364 if (one_file_system) {
365 if (file->flags & FLAG_TOP_DIR)
366 filesystem_dev = stp->st_dev;
81172142 367@@ -388,6 +519,11 @@ static void delete_in_dir(struct file_li
1fffd582
WD
368
369 dirlist = get_dirlist(fbuf, dlen, 0);
370
371+ p = fbuf + dlen;
372+ if (dlen != 1 || *fbuf != '/')
373+ *p++ = '/';
374+ remainder = MAXPATHLEN - (p - fbuf);
375+
376 /* If an item in dirlist is not found in flist, delete it
377 * from the filesystem. */
378 for (i = dirlist->count; i--; ) {
81172142 379@@ -400,15 +536,22 @@ static void delete_in_dir(struct file_li
87d0091c 380 f_name(fp, NULL));
1fffd582 381 continue;
87d0091c 382 }
1fffd582
WD
383+ if (detect_renamed && S_ISREG(fp->mode)) {
384+ strlcpy(p, fp->basename, remainder);
385+ look_for_rename(fp, fbuf, dirlist->file_pool);
386+ }
387 if (flist_find(flist, fp) < 0) {
388 f_name(fp, delbuf);
f813befd
WD
389- if (delete_delay_fp)
390+ if (delete_delay_fp && !(flags & DEL_NO_DELETIONS))
5bafda30 391 fprintf(delete_delay_fp, "%o %s%c", (short)fp->mode, delbuf, '\0');
f813befd
WD
392 else
393- delete_item(delbuf, fp->mode, NULL, DEL_RECURSE);
1fffd582 394- }
f813befd 395+ delete_item(delbuf, fp->mode, NULL, flags);
1fffd582
WD
396+ } else if (detect_renamed && S_ISDIR(fp->mode))
397+ unexplored_dirs++;
398 }
399
400+ fbuf[dlen] = '\0';
401+
402 flist_free(dirlist);
403 }
404
81172142 405@@ -438,9 +581,9 @@ static void do_delete_pass(struct file_l
1fffd582
WD
406 || !S_ISDIR(st.st_mode))
407 continue;
408
409- delete_in_dir(flist, fbuf, file, &st);
410+ delete_in_dir(flist, fbuf, file, &st, 0);
411 }
412- delete_in_dir(NULL, NULL, NULL, NULL);
413+ delete_in_dir(NULL, NULL, NULL, NULL, 0);
414
415 if (do_progress && !am_server)
416 rprintf(FINFO, " \r");
81172142 417@@ -971,6 +1114,7 @@ static int try_dests_non(struct file_str
9a70b743 418 return j;
1fffd582
WD
419 }
420
421+static struct bitbag *delayed_bits = NULL;
422 static int phase = 0;
423
424 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
81172142 425@@ -1157,8 +1301,12 @@ static void recv_generator(char *fname,
9a70b743
WD
426 if (real_ret != 0 && one_file_system)
427 real_st.st_dev = filesystem_dev;
1fffd582 428 if (delete_during && f_out != -1 && !phase && dry_run < 2
70891d26 429- && (file->flags & FLAG_XFER_DIR))
9a70b743 430- delete_in_dir(the_file_list, fname, file, &real_st);
70891d26 431+ && (file->flags & FLAG_XFER_DIR)) {
9a70b743 432+ if (detect_renamed && real_ret != 0)
1fffd582 433+ unexplored_dirs++;
9a70b743 434+ delete_in_dir(the_file_list, fname, file, &real_st,
1fffd582
WD
435+ delete_during < 0 ? DEL_NO_DELETIONS : 0);
436+ }
437 return;
438 }
439
81172142 440@@ -1429,8 +1577,14 @@ static void recv_generator(char *fname,
1fffd582
WD
441 itemizing, code, HL_SKIP))
442 return;
81172142 443 #endif
1fffd582
WD
444- if (stat_errno == ENOENT)
445+ if (stat_errno == ENOENT) {
446+ if (detect_renamed && unexplored_dirs > 0
447+ && file->length) {
448+ bitbag_set_bit(delayed_bits, ndx);
449+ return;
450+ }
451 goto notify_others;
452+ }
453 rsyserr(FERROR, stat_errno, "recv_generator: failed to stat %s",
454 full_fname(fname));
455 return;
81172142 456@@ -1619,13 +1773,19 @@ void generate_files(int f_out, struct fi
1fffd582
WD
457 (long)getpid(), flist->count);
458 }
459
460+ if (detect_renamed) {
461+ delayed_bits = bitbag_create(flist->count);
462+ if (!delete_before && !delete_during)
463+ delete_during = -1;
464+ }
465+
466 if (delete_before && !local_name && flist->count > 0)
467 do_delete_pass(flist);
f813befd
WD
468 if (delete_during == 2)
469 start_delete_temp();
1fffd582
WD
470 do_progress = 0;
471
472- if (append_mode || whole_file < 0)
473+ if (append_mode || detect_renamed || whole_file < 0)
474 whole_file = 0;
475 if (verbose >= 2) {
476 rprintf(FINFO, "delta-transmission %s\n",
81172142 477@@ -1682,7 +1842,23 @@ void generate_files(int f_out, struct fi
1fffd582
WD
478 }
479 recv_generator(NULL, NULL, 0, 0, 0, code, -1);
480 if (delete_during)
481- delete_in_dir(NULL, NULL, NULL, NULL);
482+ delete_in_dir(NULL, NULL, NULL, NULL, 0);
483+
484+ if (detect_renamed) {
485+ if (delete_during < 0)
486+ delete_during = 0;
487+ detect_renamed = 0;
488+
489+ for (i = -1; (i = bitbag_next_bit(delayed_bits, i)) >= 0; ) {
490+ struct file_struct *file = flist->files[i];
491+ if (local_name)
492+ strlcpy(fbuf, local_name, sizeof fbuf);
493+ else
494+ f_name(file, fbuf);
495+ recv_generator(fbuf, file, i, itemizing,
496+ maybe_ATTRS_REPORT, code, f_out);
497+ }
498+ }
499
500 phase++;
501 csum_length = SUM_LENGTH;
502--- old/options.c
503+++ new/options.c
03019e41 504@@ -78,6 +78,7 @@ int am_generator = 0;
a94141d9 505 int am_starting_up = 1;
1fffd582
WD
506 int relative_paths = -1;
507 int implied_dirs = 1;
508+int detect_renamed = 0;
509 int numeric_ids = 0;
510 int allow_8bit_chars = 0;
511 int force_delete = 0;
70891d26 512@@ -343,6 +344,7 @@ void usage(enum logcode F)
1fffd582
WD
513 rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
514 rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
515 rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
516+ rprintf(F," --detect-renamed try to find renamed files to speed up the transfer\n");
517 rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
518 rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
519 rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
70891d26 520@@ -497,6 +499,7 @@ static struct poptOption long_options[]
1fffd582
WD
521 {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
522 {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
523 {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
524+ {"detect-renamed", 0, POPT_ARG_NONE, &detect_renamed, 0, 0, 0 },
525 {"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 },
526 {"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
527 {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 },
70891d26 528@@ -1361,7 +1364,7 @@ int parse_arguments(int *argc, const cha
1fffd582
WD
529 inplace = 1;
530 }
531
532- if (delay_updates && !partial_dir)
533+ if ((delay_updates || detect_renamed) && !partial_dir)
534 partial_dir = tmp_partialdir;
535
536 if (inplace) {
70891d26 537@@ -1370,6 +1373,7 @@ int parse_arguments(int *argc, const cha
1fffd582
WD
538 snprintf(err_buf, sizeof err_buf,
539 "--%s cannot be used with --%s\n",
540 append_mode ? "append" : "inplace",
541+ detect_renamed ? "detect-renamed" :
542 delay_updates ? "delay-updates" : "partial-dir");
543 return 0;
544 }
70891d26 545@@ -1680,6 +1684,8 @@ void server_options(char **args,int *arg
a94141d9
WD
546 args[ac++] = "--super";
547 if (size_only)
548 args[ac++] = "--size-only";
549+ if (detect_renamed)
550+ args[ac++] = "--detect-renamed";
551 }
552
553 if (modify_window_set) {
1fffd582
WD
554--- old/rsync.yo
555+++ new/rsync.yo
f813befd 556@@ -364,6 +364,7 @@ to the detailed description below for a
1fffd582
WD
557 --modify-window=NUM compare mod-times with reduced accuracy
558 -T, --temp-dir=DIR create temporary files in directory DIR
559 -y, --fuzzy find similar file for basis if no dest file
560+ --detect-renamed try to find renamed files to speed the xfer
561 --compare-dest=DIR also compare received files relative to DIR
562 --copy-dest=DIR ... and include copies of unchanged files
563 --link-dest=DIR hardlink to files in DIR when unchanged
f813befd 564@@ -1272,6 +1273,15 @@ Note that the use of the bf(--delete) op
1fffd582
WD
565 fuzzy-match files, so either use bf(--delete-after) or specify some
566 filename exclusions if you need to prevent this.
567
568+dit(bf(--detect-renamed)) This option tells rsync to scan the receiving
569+side for files that have been renamed, and to use any that are found as
570+alternate basis files to help speed up the transfer.
571+By default, alternate-basis files are hard-linked into a directory named
572+".~tmp~" in each file's destination directory, but if you've specified
573+the bf(--partial-dir) option, that directory will be used instead. These
574+potential alternate-basis files will be removed as the transfer progresses.
575+This option conflicts with bf(--inplace) and bf(--append).
576+
577 dit(bf(--compare-dest=DIR)) This option instructs rsync to use em(DIR) on
578 the destination machine as an additional hierarchy to compare destination
579 files against doing transfers (if the files are missing in the destination
580--- old/util.c
581+++ new/util.c
f813befd 582@@ -1027,6 +1027,32 @@ int handle_partial_dir(const char *fname
1fffd582
WD
583 return 1;
584 }
585
586+/* We need to supply our own strcmp function for file list comparisons
587+ * to ensure that signed/unsigned usage is consistent between machines. */
588+int u_strcmp(const char *p1, const char *p2)
589+{
590+ for ( ; *p1; p1++, p2++) {
591+ if (*p1 != *p2)
592+ break;
593+ }
594+
595+ return (int)*(uchar*)p1 - (int)*(uchar*)p2;
596+}
597+
598+/* We need a memcmp function compares unsigned-byte values. */
599+int u_memcmp(const void *p1, const void *p2, size_t len)
600+{
601+ const uchar *u1 = p1;
602+ const uchar *u2 = p2;
603+
604+ while (len--) {
605+ if (*u1 != *u2)
606+ return (int)*u1 - (int)*u2;
607+ }
608+
609+ return 0;
610+}
611+
612 /**
613 * Determine if a symlink points outside the current directory tree.
614 * This is considered "unsafe" because e.g. when mirroring somebody