1 This patch adds the options --detect-renamed-lax and --detect-moved.
2 These modify the --detect-renamed algorithm to adopt a matching file
3 without verifying that the content is as expected. The former blindly
4 accepts a file that matches in size and modified time. The latter
5 requires that the filename also match (ignoring any renamed files).
7 This patch is EXPERIMENTAL, though it did work correctly in my light
10 To use this patch, run these commands for a successful build:
12 patch -p1 <patches/detect-renamed.diff
13 patch -p1 <patches/detect-renamed-lax.diff
14 ./configure (optional if already run)
17 FIXME: If a run with --detect-renamed-lax stages a different-basename
18 destination file and then gets interrupted, a subsequent run that
19 switches to --detect-moved blindly accepts the staged file.
21 -- Matt McCutchen <hashproduct+rsync@gmail.com>
23 diff --git a/generator.c b/generator.c
26 @@ -186,7 +186,9 @@ static int fattr_find(struct file_struct *f, char *fname)
31 + /* --detect-moved doesn't allow non-basename matches */
32 + if (detect_renamed != 3)
34 diff = u_strcmp(fmid->basename, f->basename);
37 @@ -1864,6 +1866,21 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
38 fnamecmp = partialptr;
39 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
41 + if (detect_renamed > 1 && unchanged_file(fnamecmp, file, &sx.st)) {
42 + /* Adopt the partial file. */
43 + finish_transfer(fname, fnamecmp, NULL, NULL, file, 1, 1);
44 + handle_partial_dir(partialptr, PDIR_DELETE);
46 + itemize(fnamecmp, file, ndx, -1, &sx,
47 + ITEM_LOCAL_CHANGE, fnamecmp_type, NULL);
48 +#ifdef SUPPORT_HARD_LINKS
49 + if (preserve_hard_links && F_IS_HLINKED(file))
50 + finish_hard_link(file, fname, ndx, &sx.st, itemizing, code, -1);
52 + if (remove_source_files == 1)
53 + goto return_with_success;
59 diff --git a/options.c b/options.c
62 @@ -387,6 +387,8 @@ void usage(enum logcode F)
63 rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
64 rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
65 rprintf(F," --detect-renamed try to find renamed files to speed up the transfer\n");
66 + rprintf(F," --detect-renamed-lax ... and assume identical to source files (risky!)\n");
67 + rprintf(F," --detect-moved ... only if basenames match (less risky)\n");
68 rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
69 rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
70 rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
71 @@ -565,7 +567,9 @@ static struct poptOption long_options[] = {
72 {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
73 {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
74 {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
75 - {"detect-renamed", 0, POPT_ARG_NONE, &detect_renamed, 0, 0, 0 },
76 + {"detect-renamed", 0, POPT_ARG_VAL, &detect_renamed, 1, 0, 0 },
77 + {"detect-renamed-lax",0, POPT_ARG_VAL, &detect_renamed, 2, 0, 0 },
78 + {"detect-moved", 0, POPT_ARG_VAL, &detect_renamed, 3, 0, 0 },
79 {"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 },
80 {"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
81 {"no-compress", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 },
82 @@ -1892,8 +1896,14 @@ void server_options(char **args, int *argc_p)
83 args[ac++] = "--super";
85 args[ac++] = "--size-only";
87 - args[ac++] = "--detect-renamed";
88 + if (detect_renamed) {
89 + if (detect_renamed == 1)
90 + args[ac++] = "--detect-renamed";
91 + else if (detect_renamed == 2)
92 + args[ac++] = "--detect-renamed-lax";
94 + args[ac++] = "--detect-moved";
98 if (asprintf(&arg, "--skip-compress=%s", skip_compress) < 0)
99 diff --git a/rsync.yo b/rsync.yo
102 @@ -386,6 +386,8 @@ to the detailed description below for a complete description. verb(
103 -T, --temp-dir=DIR create temporary files in directory DIR
104 -y, --fuzzy find similar file for basis if no dest file
105 --detect-renamed try to find renamed files to speed the xfer
106 + --detect-renamed-lax ...& assume identical to src files (risky!)
107 + --detect-moved ... only if basenames match (less risky)
108 --compare-dest=DIR also compare received files relative to DIR
109 --copy-dest=DIR ... and include copies of unchanged files
110 --link-dest=DIR hardlink to files in DIR when unchanged
111 @@ -1467,6 +1469,17 @@ the bf(--partial-dir) option, that directory will be used instead. These
112 potential alternate-basis files will be removed as the transfer progresses.
113 This option conflicts with bf(--inplace) and bf(--append).
115 +dit(bf(--detect-renamed-lax)) This version of bf(--detect-renamed)
116 +makes rsync hard-link em(dest/D) to em(dest/S) without verifying that
117 +em(src/S) and em(dest/S) have the same data. This poses a significant risk
118 +of corrupting the destination by representing a new source file by an
119 +unrelated destination file that coincidentally passes the quick check with the
120 +source file. Use this option only if you accept the risk and disk I/O is a
123 +dit(bf(--detect-moved)) A less risky variant of bf(--detect-renamed-lax) that
124 +only uses a destination file that has the same basename as the new source file.
126 dit(bf(--compare-dest=DIR)) This option instructs rsync to use em(DIR) on
127 the destination machine as an additional hierarchy to compare destination
128 files against doing transfers (if the files are missing in the destination