Commit | Line | Data |
---|---|---|
4afbc050 WD |
1 | This adds the option --copy-dest, which works just like --link-dest |
2 | except that identical files are copied into the destination instead | |
3 | of hard-linked. | |
4 | ||
e5718e56 WD |
5 | --- orig/generator.c 2005-03-02 17:28:17 |
6 | +++ generator.c 2005-03-02 17:30:18 | |
4afbc050 WD |
7 | @@ -65,6 +65,7 @@ extern int always_checksum; |
8 | extern char *partial_dir; | |
9 | extern char *basis_dir[]; | |
10 | extern int compare_dest; | |
11 | +extern int copy_dest; | |
12 | extern int link_dest; | |
13 | extern int whole_file; | |
14 | extern int local_server; | |
251c8a01 WD |
15 | @@ -833,6 +834,8 @@ static void recv_generator(char *fname, |
16 | continue; | |
17 | best_match = i; | |
18 | match_level = 2; | |
19 | + if (copy_dest) | |
20 | + break; | |
21 | /* FALL THROUGH */ | |
22 | case 2: | |
23 | if (!unchanged_attrs(file, &st)) | |
e5718e56 WD |
24 | @@ -862,10 +865,23 @@ static void recv_generator(char *fname, |
25 | full_fname(fnamecmpbuf), | |
26 | safe_fname(fname)); | |
251c8a01 | 27 | } |
e5718e56 WD |
28 | - match_level = 1; |
29 | + match_level = 2; | |
4afbc050 | 30 | } |
e5718e56 WD |
31 | #endif |
32 | - if (match_level && match_level < 3) { | |
33 | + if (match_level == 2) { | |
4afbc050 WD |
34 | + /* Copy the file locally. */ |
35 | + if (copy_file(fnamecmpbuf, fname, file->mode) < 0) { | |
251c8a01 WD |
36 | + if (verbose) { |
37 | + rsyserr(FINFO, errno, | |
38 | + "copy_file %s => %s", | |
39 | + full_fname(fnamecmpbuf), | |
40 | + safe_fname(fname)); | |
41 | + } | |
e5718e56 | 42 | + match_level = 0; |
251c8a01 | 43 | + statret = -1; |
4afbc050 WD |
44 | + } else |
45 | + set_perms(fname, file, NULL, 0); | |
e5718e56 | 46 | + } else if (match_level == 1) { |
4afbc050 WD |
47 | fnamecmp = fnamecmpbuf; |
48 | fnamecmp_type = i; | |
49 | } | |
e5718e56 | 50 | --- orig/options.c 2005-03-02 09:52:06 |
251c8a01 | 51 | +++ options.c 2005-03-02 10:05:21 |
4afbc050 WD |
52 | @@ -143,6 +143,7 @@ char *backup_dir = NULL; |
53 | char backup_dir_buf[MAXPATHLEN]; | |
54 | int rsync_port = 0; | |
55 | int compare_dest = 0; | |
56 | +int copy_dest = 0; | |
57 | int link_dest = 0; | |
58 | int basis_dir_cnt = 0; | |
59 | ||
60 | @@ -317,6 +318,7 @@ void usage(enum logcode F) | |
61 | rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n"); | |
62 | rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n"); | |
63 | rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n"); | |
64 | + rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n"); | |
65 | rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n"); | |
66 | rprintf(F," -z, --compress compress file data during the transfer\n"); | |
67 | rprintf(F," -C, --cvs-exclude auto-ignore files the same way CVS does\n"); | |
68 | @@ -355,7 +357,7 @@ void usage(enum logcode F) | |
69 | } | |
70 | ||
71 | enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM, | |
72 | - OPT_FILTER, OPT_COMPARE_DEST, OPT_LINK_DEST, | |
73 | + OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, | |
74 | OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, | |
75 | OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT, OPT_MAX_SIZE, | |
76 | OPT_REFUSED_BASE = 9000}; | |
77 | @@ -424,6 +426,7 @@ static struct poptOption long_options[] | |
78 | {"timeout", 0, POPT_ARG_INT, &io_timeout, OPT_TIMEOUT, 0, 0 }, | |
79 | {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 }, | |
80 | {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 }, | |
81 | + {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 }, | |
82 | {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 }, | |
83 | {"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 }, | |
84 | /* TODO: Should this take an optional int giving the compression level? */ | |
85 | @@ -838,6 +841,11 @@ int parse_arguments(int *argc, const cha | |
86 | return 0; | |
87 | #endif | |
88 | ||
89 | + case OPT_COPY_DEST: | |
90 | + copy_dest = 1; | |
91 | + dest_option = "--copy-dest"; | |
92 | + goto set_dest_dir; | |
93 | + | |
94 | case OPT_COMPARE_DEST: | |
95 | compare_dest = 1; | |
96 | dest_option = "--compare-dest"; | |
97 | @@ -928,9 +936,9 @@ int parse_arguments(int *argc, const cha | |
98 | return 0; | |
99 | } | |
100 | ||
101 | - if (compare_dest + link_dest > 1) { | |
102 | + if (compare_dest + copy_dest + link_dest > 1) { | |
103 | snprintf(err_buf, sizeof err_buf, | |
104 | - "You may not mix --compare-dest and --link-dest.\n"); | |
105 | + "You may not mix --compare-dest, --copy-dest, and --link-dest.\n"); | |
106 | return 0; | |
107 | } | |
108 | ||
251c8a01 | 109 | --- orig/rsync.yo 2005-03-02 08:52:45 |
4afbc050 WD |
110 | +++ rsync.yo 2005-02-23 02:05:34 |
111 | @@ -353,6 +353,7 @@ to the detailed description below for a | |
112 | -T, --temp-dir=DIR create temporary files in directory DIR | |
113 | -y, --fuzzy find similar file for basis if no dest file | |
114 | --compare-dest=DIR also compare received files relative to DIR | |
115 | + --copy-dest=DIR ... and include copies of unchanged files | |
116 | --link-dest=DIR hardlink to files in DIR when unchanged | |
117 | -z, --compress compress file data during the transfer | |
118 | -C, --cvs-exclude auto-ignore files in the same way CVS does | |
119 | @@ -554,8 +555,8 @@ bound. | |
120 | ||
121 | The option implies bf(--partial) (since an interrupted transfer does not delete | |
122 | the file), but conflicts with bf(--partial-dir) and bf(--delay-updates). | |
123 | -Prior to rsync 2.6.4 bf(--inplace) was also incompatible with bf(--compare-dest) | |
124 | -and bf(--link-dest). | |
125 | +Prior to rsync 2.6.4 bf(--inplace) was also incompatible with bf(--compare-dest), | |
126 | +bf(--copy-dest), and bf(--link-dest). | |
127 | ||
128 | WARNING: The file's data will be in an inconsistent state during the | |
129 | transfer (and possibly afterward if the transfer gets interrupted), so you | |
251c8a01 | 130 | @@ -957,9 +958,19 @@ finds an existing file. That first disc |
4afbc050 WD |
131 | and also determines if the transfer needs to happen. |
132 | ||
133 | If em(DIR) is a relative path, it is relative to the destination directory. | |
134 | -See also bf(--link-dest). | |
135 | +See also bf(--copy-dest) and bf(--link-dest). | |
136 | ||
137 | -dit(bf(--link-dest=DIR)) This option behaves like bf(--compare-dest), but | |
138 | +dit(bf(--copy-dest=DIR)) This option behaves like bf(--compare-dest), but | |
139 | +rsync will also copy unchanged files found in em(DIR) to the destination | |
140 | +directory (using the data in the em(DIR) for an efficient copy). This is | |
141 | +useful for doing transfers to a new destination while leaving existing | |
142 | +files intact, and then doing a flash-cutover when all files have been | |
143 | +successfully transferred. | |
144 | + | |
145 | +If em(DIR) is a relative path, it is relative to the destination directory. | |
146 | +See also bf(--compare-dest) and bf(--link-dest). | |
147 | + | |
148 | +dit(bf(--link-dest=DIR)) This option behaves like bf(--copy-dest), but | |
149 | unchanged files are hard linked from em(DIR) to the destination directory. | |
150 | The files must be identical in all preserved attributes (e.g. permissions, | |
151 | possibly ownership) in order for the files to be linked together. | |
251c8a01 | 152 | @@ -973,7 +984,7 @@ the list in the order specified), and if |
4afbc050 WD |
153 | of the em(DIR)s will be selected to try to speed up the transfer. |
154 | ||
155 | If em(DIR) is a relative path, it is relative to the destination directory. | |
156 | -See also bf(--compare-dest). | |
157 | +See also bf(--compare-dest) and bf(--copy-dest). | |
158 | ||
159 | Note that rsync versions prior to 2.6.1 had a bug that could prevent | |
160 | bf(--link-dest) from working properly for a non-root user when bf(-o) was specified | |
161 | --- orig/testsuite/compare-dest.test 2005-02-26 19:51:27 | |
162 | +++ testsuite/compare-dest.test 2005-03-01 15:57:27 | |
163 | @@ -31,9 +31,9 @@ $RSYNC -av --exclude=/text --exclude=etc | |
164 | checkit "$RSYNC -avv --no-whole-file \ | |
165 | --compare-dest=\"$alt1dir\" --compare-dest=\"$alt2dir\" \ | |
166 | \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" | |
167 | -#checkit "$RSYNC -avv --no-whole-file \ | |
168 | -# --copy-dest=\"$alt1dir\" --copy-dest=\"$alt2dir\" \ | |
169 | -# \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir" | |
170 | +checkit "$RSYNC -avv --no-whole-file \ | |
171 | + --copy-dest=\"$alt1dir\" --copy-dest=\"$alt2dir\" \ | |
172 | + \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir" | |
173 | ||
174 | # The script would have aborted on error, so getting here means we've won. | |
175 | exit 0 |