Fixed a compilation error that crept into the code.
[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;
7b80cd0e
WD
45@@ -80,6 +81,8 @@ static struct idev tmp_idev;
46 #endif
70891d26 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
7b80cd0e 54@@ -262,6 +265,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
7b80cd0e 99@@ -1414,6 +1455,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;
7b80cd0e 135@@ -91,6 +92,7 @@ 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 142 int ignore_perishable = 0;
7b80cd0e
WD
143@@ -98,12 +100,14 @@ int non_perishable_cnt = 0;
144 int maybe_ATTRS_REPORT = 0;
d16b5fd6 145
1fffd582
WD
146 static int deletion_count = 0; /* used to implement --max-delete */
147+static int unexplored_dirs = 1;
1071853f
WD
148 static int deldelay_size = 0, deldelay_cnt = 0;
149 static char *deldelay_buf = NULL;
150 static int deldelay_fd = -1;
81172142 151 static BOOL solo_file = 0;
1fffd582 152
d16b5fd6
WD
153-/* For calling delete_item() and delete_dir_contents(). */
154+/* For calling delete_item(), delete_dir_contents(), and delete_in_dir(). */
155+#define DEL_NO_DELETIONS (1<<0)
87d0091c 156 #define DEL_RECURSE (1<<1) /* recurse */
d16b5fd6 157 #define DEL_DIR_IS_EMPTY (1<<2) /* internal delete_FUNCTIONS use only */
1fffd582 158
7b80cd0e 159@@ -125,11 +129,121 @@ static int is_backup_file(char *fn)
1fffd582
WD
160 return k > 0 && strcmp(fn+k, backup_suffix) == 0;
161 }
162
163+/* Search for a regular file that matches either (1) the size & modified
164+ * time (plus the basename, if possible) or (2) the size & checksum. If
165+ * we find an exact match down to the dirname, return -1 because we found
166+ * an up-to-date file in the transfer, not a renamed file. */
167+static int fattr_find(struct file_struct *f, char *fname, alloc_pool_t pool)
168+{
169+ int low = the_fattr_list.low, high = the_fattr_list.high;
170+ int mid, ok_match = -1, good_match = -1;
171+ struct file_struct *fmid;
172+ int diff;
173+
174+ while (low <= high) {
175+ mid = (low + high) / 2;
176+ fmid = the_fattr_list.files[mid];
177+ if (fmid->length != f->length) {
178+ if (fmid->length < f->length)
179+ low = mid + 1;
180+ else
181+ high = mid - 1;
182+ continue;
183+ }
184+ if (always_checksum) {
70891d26 185+ if (!F_SUM(f)) {
1fffd582
WD
186+ if (fmid->modtime == f->modtime
187+ && f_name_cmp(fmid, f) == 0)
188+ return -1; /* assume we can't help */
70891d26
WD
189+ /* XXX update this to new checksum var idiom! */
190+ F_SUM(f) = pool_alloc(pool, MD4_SUM_LENGTH,
1fffd582 191+ "fattr_find");
70891d26 192+ file_checksum(fname, F_SUM(f), f->length);
1fffd582 193+ }
70891d26 194+ diff = u_memcmp(F_SUM(fmid), F_SUM(f), checksum_len);
1fffd582
WD
195+ if (diff) {
196+ if (diff < 0)
197+ low = mid + 1;
198+ else
199+ high = mid - 1;
200+ continue;
201+ }
202+ } else {
203+ if (fmid->modtime != f->modtime) {
204+ if (fmid->modtime < f->modtime)
205+ low = mid + 1;
206+ else
207+ high = mid - 1;
208+ continue;
209+ }
210+ }
211+ ok_match = mid;
212+ diff = u_strcmp(fmid->basename, f->basename);
213+ if (diff == 0) {
214+ good_match = mid;
215+ if (fmid->dirname == f->dirname)
216+ return -1; /* file is up-to-date */
217+ if (!fmid->dirname) {
218+ low = mid + 1;
219+ continue;
220+ }
221+ if (!f->dirname) {
222+ high = mid - 1;
223+ continue;
224+ }
225+ diff = u_strcmp(fmid->dirname, f->dirname);
226+ if (diff == 0)
227+ return -1; /* file is up-to-date */
228+ }
229+ if (diff < 0)
230+ low = mid + 1;
231+ else
232+ high = mid - 1;
233+ }
234+
235+ return good_match >= 0 ? good_match : ok_match;
236+}
237+
238+static void look_for_rename(struct file_struct *file, char *fname,
239+ alloc_pool_t pool)
240+{
241+ struct file_struct *fp;
242+ char *partialptr, *fn;
243+ STRUCT_STAT st;
244+ int ndx;
245+
246+ if ((ndx = fattr_find(file, fname, pool)) < 0)
247+ return;
248+
249+ fp = the_fattr_list.files[ndx];
250+ fn = f_name(fp, NULL);
251+ /* We don't provide an alternate-basis file if there is a basis file. */
252+ if (link_stat(fn, &st, 0) == 0)
253+ return;
254+ if ((partialptr = partial_dir_fname(fn)) == NULL
255+ || !handle_partial_dir(partialptr, PDIR_CREATE))
256+ return;
257+
258+ /* We only use the file if we can hard-link it into our tmp dir. */
259+ if (link(fname, partialptr) == 0) {
260+ if (verbose > 2) {
261+ rprintf(FINFO, "found renamed: %s => %s\n",
262+ fname, partialptr);
263+ }
264+ return;
265+ }
266+
267+ if (errno != EEXIST)
268+ handle_partial_dir(partialptr, PDIR_DELETE);
269+}
87d0091c
WD
270+
271 /* Delete a file or directory. If DEL_RECURSE is set in the flags, this will
272 * delete recursively.
1fffd582 273 *
f813befd 274 * Note that fbuf must point to a MAXPATHLEN buffer if the mode indicates it's
15894839
WD
275 * a directory! (The buffer is used for recursion, but returned unchanged.)
276+ *
277+ * Also note: --detect-rename may use this routine with DEL_NO_DELETIONS set!
278 */
f813befd 279 static enum delret delete_item(char *fbuf, int mode, char *replace, int flags)
15894839 280 {
7b80cd0e 281@@ -151,6 +265,8 @@ static enum delret delete_item(char *fbu
15894839
WD
282 goto check_ret;
283 /* OK: try to delete the directory. */
284 }
285+ if (flags & DEL_NO_DELETIONS)
286+ return DR_SUCCESS;
287
288 if (!replace && max_delete >= 0 && ++deletion_count > max_delete)
289 return DR_AT_LIMIT;
7b80cd0e 290@@ -197,6 +313,8 @@ static enum delret delete_item(char *fbu
d16b5fd6
WD
291 * its contents, otherwise just checks for content. Returns DR_SUCCESS or
292 * DR_NOT_EMPTY. Note that fname must point to a MAXPATHLEN buffer! (The
293 * buffer is used for recursion, but returned unchanged.)
1fffd582 294+ *
87d0091c 295+ * Note: --detect-rename may use this routine with DEL_NO_DELETIONS set!
1fffd582 296 */
87d0091c 297 static enum delret delete_dir_contents(char *fname, int flags)
1fffd582 298 {
7b80cd0e 299@@ -253,6 +371,8 @@ static enum delret delete_dir_contents(c
d16b5fd6
WD
300 if (S_ISDIR(fp->mode)
301 && delete_dir_contents(fname, flags | DEL_RECURSE) != DR_SUCCESS)
302 ret = DR_NOT_EMPTY;
303+ if (detect_renamed && S_ISREG(fp->mode))
304+ look_for_rename(fp, fname, dirlist->file_pool);
305 if (delete_item(fname, fp->mode, NULL, flags) != DR_SUCCESS)
306 ret = DR_NOT_EMPTY;
307 }
7b80cd0e 308@@ -405,15 +525,19 @@ static void do_delayed_deletions(char *d
1fffd582
WD
309 * all the --delete-WHEN options. Note that the fbuf pointer must point to a
310 * MAXPATHLEN buffer with the name of the directory in it (the functions we
311 * call will append names onto the end, but the old dir value will be restored
312- * on exit). */
313+ * on exit).
314+ *
315+ * Note: --detect-rename may use this routine with DEL_NO_DELETIONS set!
316+ */
317 static void delete_in_dir(struct file_list *flist, char *fbuf,
318- struct file_struct *file, STRUCT_STAT *stp)
319+ struct file_struct *file, STRUCT_STAT *stp, int flags)
320 {
321 static int min_depth = MAXPATHLEN, cur_depth = -1;
322 static void *filt_array[MAXPATHLEN/2+1];
323 static int already_warned = 0;
324 struct file_list *dirlist;
325- char delbuf[MAXPATHLEN];
326+ char *p, delbuf[MAXPATHLEN];
327+ unsigned remainder;
328 int dlen, i;
329
330 if (!flist) {
7b80cd0e 331@@ -427,6 +551,8 @@ static void delete_in_dir(struct file_li
1fffd582
WD
332 if (verbose > 2)
333 rprintf(FINFO, "delete_in_dir(%s)\n", fbuf);
334
87d0091c 335+ flags |= DEL_RECURSE;
1fffd582
WD
336+
337 if (allowed_lull)
338 maybe_send_keepalive();
339
7b80cd0e 340@@ -434,12 +560,14 @@ static void delete_in_dir(struct file_li
1fffd582
WD
341 return; /* Impossible... */
342
343 if (io_error && !(lp_ignore_errors(module_id) || ignore_errors)) {
344- if (already_warned)
345+ if (!already_warned) {
346+ rprintf(FINFO,
347+ "IO error encountered -- skipping file deletion\n");
348+ already_warned = 1;
349+ }
350+ if (!detect_renamed)
351 return;
352- rprintf(FINFO,
353- "IO error encountered -- skipping file deletion\n");
354- already_warned = 1;
355- return;
356+ flags |= DEL_NO_DELETIONS;
357 }
358
359 while (cur_depth >= file->dir.depth && cur_depth >= min_depth)
7b80cd0e 360@@ -450,6 +578,9 @@ static void delete_in_dir(struct file_li
1fffd582
WD
361 dlen = strlen(fbuf);
362 filt_array[cur_depth] = push_local_filters(fbuf, dlen);
363
364+ if (detect_renamed)
365+ unexplored_dirs--;
366+
367 if (one_file_system) {
368 if (file->flags & FLAG_TOP_DIR)
369 filesystem_dev = stp->st_dev;
7b80cd0e 370@@ -459,6 +590,11 @@ static void delete_in_dir(struct file_li
1fffd582
WD
371
372 dirlist = get_dirlist(fbuf, dlen, 0);
373
374+ p = fbuf + dlen;
375+ if (dlen != 1 || *fbuf != '/')
376+ *p++ = '/';
377+ remainder = MAXPATHLEN - (p - fbuf);
378+
379 /* If an item in dirlist is not found in flist, delete it
380 * from the filesystem. */
381 for (i = dirlist->count; i--; ) {
7b80cd0e 382@@ -471,16 +607,23 @@ static void delete_in_dir(struct file_li
87d0091c 383 f_name(fp, NULL));
1fffd582 384 continue;
87d0091c 385 }
1fffd582
WD
386+ if (detect_renamed && S_ISREG(fp->mode)) {
387+ strlcpy(p, fp->basename, remainder);
388+ look_for_rename(fp, fbuf, dirlist->file_pool);
389+ }
390 if (flist_find(flist, fp) < 0) {
391 f_name(fp, delbuf);
1071853f
WD
392- if (delete_during == 2) {
393++ if (delete_during == 2 && !(flags & DEL_NO_DELETIONS)) {
394 if (!remember_delete(fp, delbuf))
395 break;
396 } else
f813befd 397- delete_item(delbuf, fp->mode, NULL, DEL_RECURSE);
1fffd582 398- }
f813befd 399+ delete_item(delbuf, fp->mode, NULL, flags);
1fffd582
WD
400+ } else if (detect_renamed && S_ISDIR(fp->mode))
401+ unexplored_dirs++;
402 }
403
404+ fbuf[dlen] = '\0';
405+
406 flist_free(dirlist);
407 }
408
7b80cd0e 409@@ -510,9 +653,9 @@ static void do_delete_pass(struct file_l
1fffd582
WD
410 || !S_ISDIR(st.st_mode))
411 continue;
412
413- delete_in_dir(flist, fbuf, file, &st);
414+ delete_in_dir(flist, fbuf, file, &st, 0);
415 }
416- delete_in_dir(NULL, NULL, NULL, NULL);
417+ delete_in_dir(NULL, NULL, NULL, NULL, 0);
418
419 if (do_progress && !am_server)
420 rprintf(FINFO, " \r");
7b80cd0e 421@@ -1048,6 +1191,7 @@ static int try_dests_non(struct file_str
9a70b743 422 return j;
1fffd582
WD
423 }
424
425+static struct bitbag *delayed_bits = NULL;
426 static int phase = 0;
427
428 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
7b80cd0e 429@@ -1233,8 +1377,12 @@ static void recv_generator(char *fname,
9a70b743
WD
430 if (real_ret != 0 && one_file_system)
431 real_st.st_dev = filesystem_dev;
1fffd582 432 if (delete_during && f_out != -1 && !phase && dry_run < 2
70891d26 433- && (file->flags & FLAG_XFER_DIR))
9a70b743 434- delete_in_dir(the_file_list, fname, file, &real_st);
70891d26 435+ && (file->flags & FLAG_XFER_DIR)) {
9a70b743 436+ if (detect_renamed && real_ret != 0)
1fffd582 437+ unexplored_dirs++;
9a70b743 438+ delete_in_dir(the_file_list, fname, file, &real_st,
1fffd582
WD
439+ delete_during < 0 ? DEL_NO_DELETIONS : 0);
440+ }
441 return;
442 }
443
7b80cd0e
WD
444@@ -1498,8 +1646,14 @@ static void recv_generator(char *fname,
445 if (preserve_hard_links && F_NOT_HLINK_LAST(file))
1fffd582 446 return;
81172142 447 #endif
1fffd582
WD
448- if (stat_errno == ENOENT)
449+ if (stat_errno == ENOENT) {
450+ if (detect_renamed && unexplored_dirs > 0
451+ && file->length) {
452+ bitbag_set_bit(delayed_bits, ndx);
453+ return;
454+ }
455 goto notify_others;
456+ }
457 rsyserr(FERROR, stat_errno, "recv_generator: failed to stat %s",
458 full_fname(fname));
459 return;
1071853f 460@@ -1691,6 +1845,12 @@ void generate_files(int f_out, struct fi
1fffd582
WD
461 (long)getpid(), flist->count);
462 }
463
464+ if (detect_renamed) {
465+ delayed_bits = bitbag_create(flist->count);
466+ if (!delete_before && !delete_during)
467+ delete_during = -1;
468+ }
469+
470 if (delete_before && !local_name && flist->count > 0)
471 do_delete_pass(flist);
1071853f
WD
472 if (delete_during == 2) {
473@@ -1701,7 +1861,7 @@ void generate_files(int f_out, struct fi
474 }
1fffd582
WD
475 do_progress = 0;
476
477- if (append_mode || whole_file < 0)
478+ if (append_mode || detect_renamed || whole_file < 0)
479 whole_file = 0;
480 if (verbose >= 2) {
481 rprintf(FINFO, "delta-transmission %s\n",
7b80cd0e 482@@ -1757,7 +1917,23 @@ void generate_files(int f_out, struct fi
1fffd582 483 }
7b80cd0e 484 recv_generator(NULL, NULL, 0, 0, code, -1);
1fffd582
WD
485 if (delete_during)
486- delete_in_dir(NULL, NULL, NULL, NULL);
487+ delete_in_dir(NULL, NULL, NULL, NULL, 0);
488+
489+ if (detect_renamed) {
490+ if (delete_during < 0)
491+ delete_during = 0;
492+ detect_renamed = 0;
493+
494+ for (i = -1; (i = bitbag_next_bit(delayed_bits, i)) >= 0; ) {
495+ struct file_struct *file = flist->files[i];
496+ if (local_name)
497+ strlcpy(fbuf, local_name, sizeof fbuf);
498+ else
499+ f_name(file, fbuf);
500+ recv_generator(fbuf, file, i, itemizing,
501+ maybe_ATTRS_REPORT, code, f_out);
502+ }
503+ }
504
505 phase++;
506 csum_length = SUM_LENGTH;
507--- old/options.c
508+++ new/options.c
03019e41 509@@ -78,6 +78,7 @@ int am_generator = 0;
a94141d9 510 int am_starting_up = 1;
1fffd582
WD
511 int relative_paths = -1;
512 int implied_dirs = 1;
513+int detect_renamed = 0;
514 int numeric_ids = 0;
515 int allow_8bit_chars = 0;
516 int force_delete = 0;
70891d26 517@@ -343,6 +344,7 @@ void usage(enum logcode F)
1fffd582
WD
518 rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
519 rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
520 rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
521+ rprintf(F," --detect-renamed try to find renamed files to speed up the transfer\n");
522 rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
523 rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
524 rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
70891d26 525@@ -497,6 +499,7 @@ static struct poptOption long_options[]
1fffd582
WD
526 {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
527 {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
528 {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
529+ {"detect-renamed", 0, POPT_ARG_NONE, &detect_renamed, 0, 0, 0 },
530 {"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 },
531 {"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
532 {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 },
70891d26 533@@ -1361,7 +1364,7 @@ int parse_arguments(int *argc, const cha
1fffd582
WD
534 inplace = 1;
535 }
536
537- if (delay_updates && !partial_dir)
538+ if ((delay_updates || detect_renamed) && !partial_dir)
539 partial_dir = tmp_partialdir;
540
541 if (inplace) {
70891d26 542@@ -1370,6 +1373,7 @@ int parse_arguments(int *argc, const cha
1fffd582
WD
543 snprintf(err_buf, sizeof err_buf,
544 "--%s cannot be used with --%s\n",
545 append_mode ? "append" : "inplace",
546+ detect_renamed ? "detect-renamed" :
547 delay_updates ? "delay-updates" : "partial-dir");
548 return 0;
549 }
70891d26 550@@ -1680,6 +1684,8 @@ void server_options(char **args,int *arg
a94141d9
WD
551 args[ac++] = "--super";
552 if (size_only)
553 args[ac++] = "--size-only";
554+ if (detect_renamed)
555+ args[ac++] = "--detect-renamed";
556 }
557
558 if (modify_window_set) {
1fffd582
WD
559--- old/rsync.yo
560+++ new/rsync.yo
f813befd 561@@ -364,6 +364,7 @@ to the detailed description below for a
1fffd582
WD
562 --modify-window=NUM compare mod-times with reduced accuracy
563 -T, --temp-dir=DIR create temporary files in directory DIR
564 -y, --fuzzy find similar file for basis if no dest file
565+ --detect-renamed try to find renamed files to speed the xfer
566 --compare-dest=DIR also compare received files relative to DIR
567 --copy-dest=DIR ... and include copies of unchanged files
568 --link-dest=DIR hardlink to files in DIR when unchanged
f813befd 569@@ -1272,6 +1273,15 @@ Note that the use of the bf(--delete) op
1fffd582
WD
570 fuzzy-match files, so either use bf(--delete-after) or specify some
571 filename exclusions if you need to prevent this.
572
573+dit(bf(--detect-renamed)) This option tells rsync to scan the receiving
574+side for files that have been renamed, and to use any that are found as
575+alternate basis files to help speed up the transfer.
576+By default, alternate-basis files are hard-linked into a directory named
577+".~tmp~" in each file's destination directory, but if you've specified
578+the bf(--partial-dir) option, that directory will be used instead. These
579+potential alternate-basis files will be removed as the transfer progresses.
580+This option conflicts with bf(--inplace) and bf(--append).
581+
582 dit(bf(--compare-dest=DIR)) This option instructs rsync to use em(DIR) on
583 the destination machine as an additional hierarchy to compare destination
584 files against doing transfers (if the files are missing in the destination
585--- old/util.c
586+++ new/util.c
f813befd 587@@ -1027,6 +1027,32 @@ int handle_partial_dir(const char *fname
1fffd582
WD
588 return 1;
589 }
590
591+/* We need to supply our own strcmp function for file list comparisons
592+ * to ensure that signed/unsigned usage is consistent between machines. */
593+int u_strcmp(const char *p1, const char *p2)
594+{
595+ for ( ; *p1; p1++, p2++) {
596+ if (*p1 != *p2)
597+ break;
598+ }
599+
600+ return (int)*(uchar*)p1 - (int)*(uchar*)p2;
601+}
602+
603+/* We need a memcmp function compares unsigned-byte values. */
604+int u_memcmp(const void *p1, const void *p2, size_t len)
605+{
606+ const uchar *u1 = p1;
607+ const uchar *u2 = p2;
608+
609+ while (len--) {
610+ if (*u1 != *u2)
611+ return (int)*u1 - (int)*u2;
612+ }
613+
614+ return 0;
615+}
616+
617 /**
618 * Determine if a symlink points outside the current directory tree.
619 * This is considered "unsafe" because e.g. when mirroring somebody