1 Depends-On-Patch: g2r-basis-filename.diff
3 This patch allows multiple --compare-dest or --link-dest options to be
4 used, making the transfer of some files more optimal. Note that the
5 algorithm does NOT search for the best match -- it stops at the first
6 match and uses that as the basis file for the transfer, so be sure to
7 order your arguments appropriately (the args are searched in the order
10 Before compiling, be sure to run "make proto".
12 --- orig/generator.c 2004-10-09 04:06:49
13 +++ generator.c 2004-10-09 03:35:50
14 @@ -45,7 +45,7 @@ extern int io_timeout;
15 extern int protocol_version;
16 extern int always_checksum;
17 extern char *partial_dir;
18 -extern char *compare_dest;
19 +extern char *compare_dest[];
21 extern int whole_file;
22 extern int local_server;
23 @@ -424,11 +424,19 @@ static void recv_generator(char *fname,
25 fnamecmp_type = G2R_FNAME;
27 - if (statret == -1 && compare_dest != NULL) {
28 + if (statret == -1 && compare_dest[0] != NULL) {
29 /* try the file at compare_dest instead */
30 - pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, compare_dest, fname);
31 - if (link_stat(fnamecmpbuf, &st, 0) == 0
32 - && S_ISREG(st.st_mode)) {
35 + pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
36 + compare_dest[i], fname);
37 + if (link_stat(fnamecmpbuf, &st, 0) == 0
38 + && S_ISREG(st.st_mode)) {
42 + } while (compare_dest[++i] != NULL);
45 if (link_dest && !dry_run) {
46 if (do_link(fnamecmpbuf, fname) < 0) {
47 @@ -439,15 +447,14 @@ static void recv_generator(char *fname,
50 fnamecmp = fnamecmpbuf;
57 fnamecmp = fnamecmpbuf;
65 --- orig/main.c 2004-10-09 03:25:43
66 +++ main.c 2004-07-30 07:23:54
67 @@ -59,7 +59,7 @@ extern int filesfrom_fd;
68 extern pid_t cleanup_child_pid;
69 extern char *files_from;
70 extern char *remote_filesfrom_file;
71 -extern char *compare_dest;
72 +extern char *compare_dest[];
73 extern char *rsync_path;
74 extern char *shell_cmd;
75 extern char *batch_name;
76 @@ -463,7 +463,7 @@ static int do_recv(int f_in,int f_out,st
79 int error_pipe[2], name_pipe[2];
80 - BOOL need_name_pipe = compare_dest && !dry_run;
81 + BOOL need_name_pipe = compare_dest[0] && !dry_run;
83 /* The receiving side mustn't obey this, or an existing symlink that
84 * points to an identical file won't be replaced by the referent. */
85 --- orig/options.c 2004-10-14 17:11:40
86 +++ options.c 2004-10-14 17:13:57
87 @@ -114,12 +114,13 @@ int write_batch = 0;
89 int backup_dir_len = 0;
90 int backup_suffix_len;
91 +int num_comp_dest = 0;
92 unsigned int backup_dir_remainder;
94 char *backup_suffix = NULL;
96 char *partial_dir = NULL;
97 -char *compare_dest = NULL;
98 +char *compare_dest[MAX_COMP_DEST+1];
99 char *config_file = NULL;
100 char *shell_cmd = NULL;
101 char *log_format = NULL;
102 @@ -140,6 +141,7 @@ char *batch_name = NULL;
104 static int daemon_opt; /* sets am_daemon after option error-reporting */
105 static int modify_window_set;
106 +static int saw_compare_dest = 0;
108 /** Local address to bind. As a character string because it's
109 * interpreted by the IPv6 layer: should be a numeric IP4 or IP6
110 @@ -310,7 +312,7 @@ void usage(enum logcode F)
113 enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
114 - OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
115 + OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_COMPARE_DEST, OPT_LINK_DEST,
116 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
117 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT,
118 OPT_REFUSED_BASE = 9000};
119 @@ -369,8 +371,8 @@ static struct poptOption long_options[]
120 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
121 {"timeout", 0, POPT_ARG_INT, &io_timeout, OPT_TIMEOUT, 0, 0 },
122 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
123 - {"compare-dest", 0, POPT_ARG_STRING, &compare_dest, 0, 0, 0 },
124 - {"link-dest", 0, POPT_ARG_STRING, &compare_dest, OPT_LINK_DEST, 0, 0 },
125 + {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
126 + {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
127 /* TODO: Should this take an optional int giving the compression level? */
128 {"compress", 'z', POPT_ARG_NONE, &do_compression, 0, 0, 0 },
129 {"stats", 0, POPT_ARG_NONE, &do_stats, 0, 0, 0 },
130 @@ -672,8 +674,28 @@ int parse_arguments(int *argc, const cha
131 select_timeout = io_timeout;
134 + case OPT_COMPARE_DEST:
135 + if (num_comp_dest >= MAX_COMP_DEST-1) {
136 + rprintf(FERROR, "ERROR: %s\n", "too many --compare-dest args given");
139 + arg = poptGetOptArg(pc);
140 + if (sanitize_paths)
141 + arg = sanitize_path(NULL, arg, NULL, 0);
142 + compare_dest[num_comp_dest++] = (char *)arg;
143 + saw_compare_dest = 1;
148 + if (num_comp_dest >= MAX_COMP_DEST-1) {
149 + rprintf(FERROR, "ERROR: %s\n", "too many --link-dest args given");
152 + arg = poptGetOptArg(pc);
153 + if (sanitize_paths)
154 + arg = sanitize_path(NULL, arg, NULL, 0);
155 + compare_dest[num_comp_dest++] = (char *)arg;
159 @@ -765,6 +787,11 @@ int parse_arguments(int *argc, const cha
163 + if (saw_compare_dest && link_dest) {
165 + "WARNING: promoting --compare-dest options to --link-dest.\n");
171 @@ -792,8 +819,6 @@ int parse_arguments(int *argc, const cha
172 tmpdir = sanitize_path(NULL, tmpdir, NULL, 0);
174 partial_dir = sanitize_path(NULL, partial_dir, NULL, 0);
176 - compare_dest = sanitize_path(NULL, compare_dest, NULL, 0);
178 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0);
180 @@ -801,6 +826,7 @@ int parse_arguments(int *argc, const cha
182 if (server_exclude_list.head && !am_sender) {
183 struct exclude_list_struct *elp = &server_exclude_list;
186 clean_fname(tmpdir, 1);
187 if (check_exclude(elp, tmpdir, 1) < 0)
188 @@ -811,9 +837,9 @@ int parse_arguments(int *argc, const cha
189 if (check_exclude(elp, partial_dir, 1) < 0)
190 goto options_rejected;
192 - if (compare_dest) {
193 - clean_fname(compare_dest, 1);
194 - if (check_exclude(elp, compare_dest, 1) < 0)
195 + for (i = 0; i < num_comp_dest; i++) {
196 + clean_fname(compare_dest[i], 1);
197 + if (check_exclude(elp, compare_dest[i], 1) < 0)
198 goto options_rejected;
201 @@ -884,7 +910,7 @@ int parse_arguments(int *argc, const cha
202 am_server ? "server" : "client");
205 - if (compare_dest) {
206 + if (saw_compare_dest || link_dest) {
207 snprintf(err_buf, sizeof err_buf,
208 "--inplace does not yet work with %s\n",
209 link_dest ? "--link-dest" : "--compare-dest");
210 @@ -951,8 +977,8 @@ int parse_arguments(int *argc, const cha
212 void server_options(char **args,int *argc)
214 + static char argstr[50+MAX_COMP_DEST*2];
216 - static char argstr[50];
220 @@ -1135,13 +1161,16 @@ void server_options(char **args,int *arg
224 - if (compare_dest && am_sender) {
225 + if (compare_dest[0] && am_sender) {
226 /* the server only needs this option if it is not the sender,
227 * and it may be an older version that doesn't know this
228 * option, so don't send it if client is the sender.
230 - args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
231 - args[ac++] = compare_dest;
233 + for (i = 0; i < num_comp_dest; i++) {
234 + args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
235 + args[ac++] = compare_dest[i];
239 if (files_from && (!am_sender || remote_filesfrom_file)) {
240 --- orig/receiver.c 2004-09-07 21:57:20
241 +++ receiver.c 2004-07-30 07:31:12
242 @@ -38,7 +38,7 @@ extern int cvs_exclude;
245 extern char *partial_dir;
246 -extern char *compare_dest;
247 +extern char *compare_dest[];
248 extern int make_backups;
249 extern int do_progress;
250 extern char *backup_dir;
251 @@ -438,7 +438,8 @@ int recv_files(int f_in, struct file_lis
252 partialptr = partial_dir ? partial_dir_fname(fname) : fname;
254 if (f_in_name >= 0) {
255 - switch (read_byte(f_in_name)) {
257 + switch (j = read_byte(f_in_name)) {
261 @@ -450,7 +451,7 @@ int recv_files(int f_in, struct file_lis
264 pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
265 - compare_dest, fname);
266 + compare_dest[j], fname);
267 fnamecmp = fnamecmpbuf;
270 --- orig/rsync.h 2004-09-07 21:52:22
271 +++ rsync.h 2004-07-30 07:23:54
274 #define MAX_ARGS 1000
276 +#define MAX_COMP_DEST 20
280 #define NO_EXCLUDES 0