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