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-07-22 00:05:38
13 +++ generator.c 2004-07-19 08:32:53
14 @@ -42,7 +42,7 @@ extern int size_only;
15 extern int io_timeout;
16 extern int protocol_version;
17 extern int always_checksum;
18 -extern char *compare_dest;
19 +extern char *compare_dest[];
21 extern int whole_file;
22 extern int local_server;
23 @@ -79,13 +79,12 @@ static int skip_file(char *fname, struct
24 if (always_checksum && S_ISREG(st->st_mode)) {
25 char sum[MD4_SUM_LENGTH];
26 char fnamecmpdest[MAXPATHLEN];
29 - if (compare_dest != NULL) {
30 - if (access(fname, 0) != 0) {
31 - pathjoin(fnamecmpdest, sizeof fnamecmpdest,
32 - compare_dest, fname);
33 - fname = fnamecmpdest;
35 + for (i = 0; compare_dest[i] != NULL && access(fname, 0) < 0; i++) {
36 + pathjoin(fnamecmpdest, sizeof fnamecmpdest,
37 + compare_dest[i], fname);
38 + fname = fnamecmpdest;
40 file_checksum(fname,sum,st->st_size);
41 return memcmp(sum, file->u.sum, protocol_version < 21 ? 2
42 @@ -414,13 +413,18 @@ static void recv_generator(char *fname,
46 - if (statret == -1 && compare_dest != NULL) {
47 + if (statret == -1 && compare_dest[0] != NULL) {
48 /* try the file at compare_dest instead */
49 int saveerrno = errno;
50 - pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, compare_dest, fname);
51 - statret = link_stat(fnamecmpbuf, &st, 0);
52 - if (!S_ISREG(st.st_mode))
55 + for (i = 0; compare_dest[i] != NULL; i++) {
56 + pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, compare_dest[i], fname);
57 + if ((statret = link_stat(fnamecmpbuf, &st, 0)) == 0) {
58 + if (S_ISREG(st.st_mode))
66 --- orig/main.c 2004-07-22 00:10:43
67 +++ main.c 2004-07-22 00:30:38
68 @@ -58,7 +58,7 @@ extern int filesfrom_fd;
69 extern pid_t cleanup_child_pid;
70 extern char *files_from;
71 extern char *remote_filesfrom_file;
72 -extern char *compare_dest;
73 +extern char *compare_dest[];
74 extern char *rsync_path;
75 extern char *shell_cmd;
76 extern char *batch_name;
77 @@ -456,7 +456,7 @@ static int do_recv(int f_in,int f_out,st
80 int error_pipe[2], name_pipe[2];
81 - int need_name_pipe = compare_dest;
82 + int need_name_pipe = compare_dest[0];
84 if (preserve_hard_links)
85 init_hard_links(flist);
86 --- orig/options.c 2004-07-21 23:59:35
87 +++ options.c 2004-07-03 17:33:30
88 @@ -118,7 +118,8 @@ unsigned int backup_dir_remainder;
90 char *backup_suffix = NULL;
92 -char *compare_dest = NULL;
93 +char *compare_dest[MAX_COMP_DEST+1];
94 +int num_comp_dest = 0;
95 char *config_file = NULL;
96 char *shell_cmd = NULL;
97 char *log_format = NULL;
98 @@ -139,6 +140,7 @@ char *batch_name = NULL;
100 static int daemon_opt; /* sets am_daemon after option error-reporting */
101 static int modify_window_set;
102 +static int saw_compare_dest = 0;
104 /** Local address to bind. As a character string because it's
105 * interpreted by the IPv6 layer: should be a numeric IP4 or IP6
106 @@ -314,7 +316,7 @@ void usage(enum logcode F)
109 enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
110 - OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
111 + OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_COMPARE_DEST, OPT_LINK_DEST,
112 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
113 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT,
114 OPT_REFUSED_BASE = 9000};
115 @@ -373,8 +375,8 @@ static struct poptOption long_options[]
116 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
117 {"timeout", 0, POPT_ARG_INT, &io_timeout, OPT_TIMEOUT, 0, 0 },
118 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
119 - {"compare-dest", 0, POPT_ARG_STRING, &compare_dest, 0, 0, 0 },
120 - {"link-dest", 0, POPT_ARG_STRING, &compare_dest, OPT_LINK_DEST, 0, 0 },
121 + {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
122 + {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
123 /* TODO: Should this take an optional int giving the compression level? */
124 {"compress", 'z', POPT_ARG_NONE, &do_compression, 0, 0, 0 },
125 {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 },
126 @@ -590,8 +592,36 @@ int parse_arguments(int *argc, const cha
127 select_timeout = io_timeout;
130 + case OPT_COMPARE_DEST:
132 + if (num_comp_dest >= MAX_COMP_DEST-1) {
133 + rprintf(FERROR, "ERROR: %s\n", "too many --compare-dest args given");
136 + arg = poptGetOptArg(pc);
137 + if (sanitize_paths)
138 + arg = alloc_sanitize_path(arg, curr_dir);
139 + compare_dest[num_comp_dest++] = (char *)arg;
140 + saw_compare_dest = 1;
143 + snprintf(err_buf, sizeof err_buf,
144 + "hard links are not supported on this %s\n",
145 + am_server ? "server" : "client");
146 + rprintf(FERROR, "ERROR: %s", err_buf);
152 + if (num_comp_dest >= MAX_COMP_DEST-1) {
153 + rprintf(FERROR, "ERROR: %s\n", "too many --link-dest args given");
156 + arg = poptGetOptArg(pc);
157 + if (sanitize_paths)
158 + arg = alloc_sanitize_path(arg, curr_dir);
159 + compare_dest[num_comp_dest++] = (char *)arg;
163 @@ -689,6 +719,11 @@ int parse_arguments(int *argc, const cha
164 exit_cleanup(RERR_SYNTAX);
167 + if (saw_compare_dest && link_dest) {
169 + "WARNING: promoting --compare-dest options to --link-dest.\n");
175 @@ -717,8 +752,6 @@ int parse_arguments(int *argc, const cha
176 (*argv)[i] = alloc_sanitize_path((*argv)[i], NULL);
178 tmpdir = alloc_sanitize_path(tmpdir, curr_dir);
180 - compare_dest = alloc_sanitize_path(compare_dest, curr_dir);
182 backup_dir = alloc_sanitize_path(backup_dir, curr_dir);
184 @@ -824,8 +857,8 @@ int parse_arguments(int *argc, const cha
186 void server_options(char **args,int *argc)
188 + static char argstr[50+MAX_COMP_DEST*2];
190 - static char argstr[50];
194 @@ -1003,13 +1036,16 @@ void server_options(char **args,int *arg
198 - if (compare_dest && am_sender) {
199 + if (compare_dest[0] && am_sender) {
200 /* the server only needs this option if it is not the sender,
201 * and it may be an older version that doesn't know this
202 * option, so don't send it if client is the sender.
204 - args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
205 - args[ac++] = compare_dest;
207 + for (i = 0; i < num_comp_dest; i++) {
208 + args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
209 + args[ac++] = compare_dest[i];
213 if (files_from && (!am_sender || remote_filesfrom_file)) {
214 --- orig/receiver.c 2004-07-22 00:20:50
215 +++ receiver.c 2004-07-03 20:14:37
216 @@ -38,7 +38,6 @@ extern int preserve_perms;
217 extern int cvs_exclude;
220 -extern char *compare_dest;
221 extern int make_backups;
222 extern int do_progress;
223 extern char *backup_dir;
224 --- orig/rsync.h 2004-07-20 21:36:08
225 +++ rsync.h 2004-07-03 17:33:30
228 #define MAX_ARGS 1000
230 +#define MAX_COMP_DEST 20
234 #define NO_EXCLUDES 0