1 This patch allows multiple --compare-dest or --link-dest options to be
2 used, making the transfer of some files more optimal. Note that the
3 algorithm does NOT search for the best match -- it stops at the first
4 match and uses that as the basis file for the transfer, so be sure to
5 order your arguments appropriately (the args are searched in the order
8 Before compiling, be sure to run "make proto".
10 --- orig/generator.c 2004-11-11 22:13:09
11 +++ generator.c 2004-11-03 22:47:23
12 @@ -46,7 +46,7 @@ extern int io_timeout;
13 extern int protocol_version;
14 extern int always_checksum;
15 extern char *partial_dir;
16 -extern char *compare_dest;
17 +extern char *compare_dest[];
19 extern int whole_file;
20 extern int local_server;
21 @@ -429,11 +429,19 @@ static void recv_generator(char *fname,
23 fnamecmp_type = FNAMECMP_FNAME;
25 - if (statret == -1 && compare_dest != NULL) {
26 + if (statret == -1 && compare_dest[0] != NULL) {
27 /* try the file at compare_dest instead */
28 - pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, compare_dest, fname);
29 - if (link_stat(fnamecmpbuf, &st, 0) == 0
30 - && S_ISREG(st.st_mode)) {
33 + pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
34 + compare_dest[i], fname);
35 + if (link_stat(fnamecmpbuf, &st, 0) == 0
36 + && S_ISREG(st.st_mode)) {
40 + } while (compare_dest[++i] != NULL);
43 if (link_dest && !dry_run) {
44 if (do_link(fnamecmpbuf, fname) < 0) {
45 @@ -444,15 +452,14 @@ static void recv_generator(char *fname,
48 fnamecmp = fnamecmpbuf;
49 - fnamecmp_type = FNAMECMP_CMPDEST;
50 + fnamecmp_type = FNAMECMP_CMPDEST + i;
55 fnamecmp = fnamecmpbuf;
56 - fnamecmp_type = FNAMECMP_CMPDEST;
57 + fnamecmp_type = FNAMECMP_CMPDEST + i;
63 --- orig/main.c 2004-11-25 16:32:40
64 +++ main.c 2004-07-30 07:23:54
65 @@ -59,7 +59,7 @@ extern int filesfrom_fd;
66 extern pid_t cleanup_child_pid;
67 extern char *files_from;
68 extern char *remote_filesfrom_file;
69 -extern char *compare_dest;
70 +extern char *compare_dest[];
71 extern char *rsync_path;
72 extern char *shell_cmd;
73 extern char *batch_name;
74 @@ -463,7 +463,7 @@ static int do_recv(int f_in,int f_out,st
77 int error_pipe[2], name_pipe[2];
78 - BOOL need_name_pipe = compare_dest && !dry_run;
79 + BOOL need_name_pipe = compare_dest[0] && !dry_run;
81 /* The receiving side mustn't obey this, or an existing symlink that
82 * points to an identical file won't be replaced by the referent. */
83 --- orig/options.c 2004-11-17 19:41:31
84 +++ options.c 2004-11-25 16:38:16
85 @@ -116,12 +116,13 @@ int write_batch = 0;
87 int backup_dir_len = 0;
88 int backup_suffix_len;
89 +int num_comp_dest = 0;
90 unsigned int backup_dir_remainder;
92 char *backup_suffix = NULL;
94 char *partial_dir = NULL;
95 -char *compare_dest = NULL;
96 +char *compare_dest[MAX_COMP_DEST+1];
97 char *config_file = NULL;
98 char *shell_cmd = NULL;
99 char *log_format = NULL;
100 @@ -142,6 +143,7 @@ char *batch_name = NULL;
102 static int daemon_opt; /* sets am_daemon after option error-reporting */
103 static int modify_window_set;
104 +static int saw_compare_dest = 0;
105 static char *max_size_arg;
107 /** Local address to bind. As a character string because it's
108 @@ -314,7 +316,7 @@ void usage(enum logcode F)
111 enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
112 - OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
113 + OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_COMPARE_DEST, OPT_LINK_DEST,
114 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
115 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT, OPT_MAX_SIZE,
116 OPT_REFUSED_BASE = 9000};
117 @@ -374,8 +376,8 @@ static struct poptOption long_options[]
118 {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 },
119 {"timeout", 0, POPT_ARG_INT, &io_timeout, OPT_TIMEOUT, 0, 0 },
120 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
121 - {"compare-dest", 0, POPT_ARG_STRING, &compare_dest, 0, 0, 0 },
122 - {"link-dest", 0, POPT_ARG_STRING, &compare_dest, OPT_LINK_DEST, 0, 0 },
123 + {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
124 + {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
125 /* TODO: Should this take an optional int giving the compression level? */
126 {"compress", 'z', POPT_ARG_NONE, &do_compression, 0, 0, 0 },
127 {"stats", 0, POPT_ARG_NONE, &do_stats, 0, 0, 0 },
128 @@ -712,7 +714,7 @@ int parse_arguments(int *argc, const cha
135 snprintf(err_buf, sizeof err_buf,
136 "hard links are not supported on this %s\n",
137 @@ -720,6 +722,20 @@ int parse_arguments(int *argc, const cha
141 + case OPT_COMPARE_DEST:
142 + saw_compare_dest = 1;
144 + if (num_comp_dest >= MAX_COMP_DEST-1) {
145 + rprintf(FERROR, "ERROR: too many %s args given\n",
146 + link_dest ? "--link-dest" : "--compare-dest");
149 + arg = poptGetOptArg(pc);
150 + if (sanitize_paths)
151 + arg = sanitize_path(NULL, arg, NULL, 0);
152 + compare_dest[num_comp_dest++] = (char *)arg;
156 /* A large opt value means that set_refuse_options()
157 * turned this option off (opt-BASE is its index). */
158 @@ -802,6 +818,11 @@ int parse_arguments(int *argc, const cha
162 + if (saw_compare_dest && link_dest) {
164 + "WARNING: promoting --compare-dest options to --link-dest.\n");
170 @@ -829,8 +850,6 @@ int parse_arguments(int *argc, const cha
171 tmpdir = sanitize_path(NULL, tmpdir, NULL, 0);
173 partial_dir = sanitize_path(NULL, partial_dir, NULL, 0);
175 - compare_dest = sanitize_path(NULL, compare_dest, NULL, 0);
177 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0);
179 @@ -838,6 +857,7 @@ int parse_arguments(int *argc, const cha
181 if (server_exclude_list.head && !am_sender) {
182 struct exclude_list_struct *elp = &server_exclude_list;
185 clean_fname(tmpdir, 1);
186 if (check_exclude(elp, tmpdir, 1) < 0)
187 @@ -848,9 +868,9 @@ int parse_arguments(int *argc, const cha
188 if (check_exclude(elp, partial_dir, 1) < 0)
189 goto options_rejected;
191 - if (compare_dest) {
192 - clean_fname(compare_dest, 1);
193 - if (check_exclude(elp, compare_dest, 1) < 0)
194 + for (i = 0; i < num_comp_dest; i++) {
195 + clean_fname(compare_dest[i], 1);
196 + if (check_exclude(elp, compare_dest[i], 1) < 0)
197 goto options_rejected;
200 @@ -923,7 +943,7 @@ int parse_arguments(int *argc, const cha
201 am_server ? "server" : "client");
204 - if (compare_dest) {
205 + if (saw_compare_dest || link_dest) {
206 snprintf(err_buf, sizeof err_buf,
207 "--inplace does not yet work with %s\n",
208 link_dest ? "--link-dest" : "--compare-dest");
209 @@ -990,8 +1010,8 @@ int parse_arguments(int *argc, const cha
211 void server_options(char **args,int *argc)
213 + static char argstr[50+MAX_COMP_DEST*2];
215 - static char argstr[50];
219 @@ -1179,13 +1199,16 @@ void server_options(char **args,int *arg
223 - if (compare_dest && am_sender) {
224 + if (compare_dest[0] && am_sender) {
225 /* the server only needs this option if it is not the sender,
226 * and it may be an older version that doesn't know this
227 * option, so don't send it if client is the sender.
229 - args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
230 - args[ac++] = compare_dest;
232 + for (i = 0; i < num_comp_dest; i++) {
233 + args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
234 + args[ac++] = compare_dest[i];
238 if (files_from && (!am_sender || remote_filesfrom_file)) {
239 --- orig/receiver.c 2004-11-03 20:30:45
240 +++ receiver.c 2004-11-03 22:50:43
241 @@ -39,7 +39,7 @@ extern int cvs_exclude;
244 extern char *partial_dir;
245 -extern char *compare_dest;
246 +extern char *compare_dest[];
247 extern int make_backups;
248 extern int do_progress;
249 extern char *backup_dir;
250 @@ -439,7 +439,8 @@ int recv_files(int f_in, struct file_lis
251 partialptr = partial_dir ? partial_dir_fname(fname) : fname;
253 if (f_in_name >= 0) {
254 - switch (read_byte(f_in_name)) {
256 + switch (j = read_byte(f_in_name)) {
260 @@ -452,7 +453,7 @@ int recv_files(int f_in, struct file_lis
261 case FNAMECMP_CMPDEST:
263 pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
264 - compare_dest, fname);
265 + compare_dest[j], fname);
266 fnamecmp = fnamecmpbuf;
269 --- orig/rsync.h 2004-11-03 20:30:45
270 +++ rsync.h 2004-07-30 07:23:54
273 #define MAX_ARGS 1000
275 +#define MAX_COMP_DEST 20
279 #define NO_EXCLUDES 0
280 --- orig/testsuite/compare-dest.test 2004-07-23 17:16:13
281 +++ testsuite/compare-dest.test 2004-11-25 16:56:33
286 -altdir="$tmpdir/alt"
287 +alt1dir="$tmpdir/alt1"
288 +alt2dir="$tmpdir/alt2"
290 # Build some files/dirs/links to copy
294 # Setup the alt and chk dirs
295 -$RSYNC -av --include=text --include='*/' --exclude='*' "$fromdir/" "$altdir/"
296 +$RSYNC -av --include=text --include='*/' --exclude='*' "$fromdir/" "$alt1dir/"
297 +$RSYNC -av --include=etc-ltr-list --include='*/' --exclude='*' "$fromdir/" "$alt2dir/"
300 touch "$fromdir/dir/text"
302 -$RSYNC -av --exclude=/text "$fromdir/" "$chkdir/"
303 +$RSYNC -av --exclude=/text --exclude=etc-ltr-list "$fromdir/" "$chkdir/"
306 -checkit "$RSYNC -avv --no-whole-file --compare-dest=\"$altdir\" \
307 +checkit "$RSYNC -avv --no-whole-file \
308 + --compare-dest=\"$alt1dir\" --compare-dest=\"$alt2dir\" \
309 \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
311 # The script would have aborted on error, so getting here means we've won.