Got rid of failing or fuzzy hunks.
[rsync/rsync-patches.git] / compare-dest.diff
CommitLineData
824abc86
WD
1Depends-On-Patch: g2r-basis-filename.diff
2
09add1ae
WD
3This patch allows multiple --compare-dest or --link-dest options to be
4used, making the transfer of some files more optimal. Note that the
5algorithm does NOT search for the best match -- it stops at the first
6match and uses that as the basis file for the transfer, so be sure to
8dd60649
WD
7order your arguments appropriately (the args are searched in the order
8they are suppled).
09add1ae 9
8dd60649
WD
10Before compiling, be sure to run "make proto".
11
b952a177
WD
12--- orig/generator.c 2004-07-28 10:14:15
13+++ generator.c 2004-07-28 10:19:57
14@@ -43,7 +43,7 @@ extern int io_timeout;
09add1ae
WD
15 extern int protocol_version;
16 extern int always_checksum;
b952a177 17 extern char *partial_dir;
09add1ae
WD
18-extern char *compare_dest;
19+extern char *compare_dest[];
20 extern int link_dest;
21 extern int whole_file;
22 extern int local_server;
b952a177 23@@ -80,13 +80,12 @@ static int skip_file(char *fname, struct
09add1ae
WD
24 if (always_checksum && S_ISREG(st->st_mode)) {
25 char sum[MD4_SUM_LENGTH];
26 char fnamecmpdest[MAXPATHLEN];
27+ int i;
28
29- if (compare_dest != NULL) {
30- if (access(fname, 0) != 0) {
31- pathjoin(fnamecmpdest, sizeof fnamecmpdest,
32- compare_dest, fname);
33- fname = fnamecmpdest;
34- }
4c189bcd 35+ for (i = 0; compare_dest[i] != NULL && access(fname, 0) < 0; i++) {
09add1ae
WD
36+ pathjoin(fnamecmpdest, sizeof fnamecmpdest,
37+ compare_dest[i], fname);
38+ fname = fnamecmpdest;
39 }
40 file_checksum(fname,sum,st->st_size);
41 return memcmp(sum, file->u.sum, protocol_version < 21 ? 2
b952a177 42@@ -422,11 +421,18 @@ static void recv_generator(char *fname,
09add1ae
WD
43
44 fnamecmp = fname;
45
46- if (statret == -1 && compare_dest != NULL) {
47+ if (statret == -1 && compare_dest[0] != NULL) {
48 /* try the file at compare_dest instead */
09add1ae 49- pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, compare_dest, fname);
b952a177
WD
50- if (link_stat(fnamecmpbuf, &st, 0) == 0
51- && S_ISREG(st.st_mode)) {
09add1ae
WD
52+ int i;
53+ for (i = 0; compare_dest[i] != NULL; i++) {
54+ pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, compare_dest[i], fname);
b952a177
WD
55+ if (link_stat(fnamecmpbuf, &st, 0) == 0
56+ && S_ISREG(st.st_mode)) {
57+ statret = 0;
58+ break;
09add1ae
WD
59+ }
60+ }
b952a177
WD
61+ if (statret == 0) {
62 #if HAVE_LINK
63 if (link_dest && !dry_run) {
64 if (do_link(fnamecmpbuf, fname) < 0) {
65@@ -442,7 +448,6 @@ static void recv_generator(char *fname,
66 } else
67 #endif
68 fnamecmp = fnamecmpbuf;
69- statret = 0;
70 } else
824abc86 71 *fnamecmpbuf = '\0';
b952a177 72 } else
2f5fa77e
WD
73--- orig/main.c 2004-07-22 00:10:43
74+++ main.c 2004-07-22 00:30:38
75@@ -58,7 +58,7 @@ extern int filesfrom_fd;
495f1899
WD
76 extern pid_t cleanup_child_pid;
77 extern char *files_from;
78 extern char *remote_filesfrom_file;
79-extern char *compare_dest;
80+extern char *compare_dest[];
81 extern char *rsync_path;
82 extern char *shell_cmd;
83 extern char *batch_name;
c2530f70 84@@ -458,7 +458,7 @@ static int do_recv(int f_in,int f_out,st
495f1899
WD
85 int pid;
86 int status = 0;
87 int error_pipe[2], name_pipe[2];
c2530f70
WD
88- BOOL need_name_pipe = compare_dest && !dry_run;
89+ BOOL need_name_pipe = compare_dest[0] && !dry_run;
495f1899
WD
90
91 if (preserve_hard_links)
92 init_hard_links(flist);
b952a177
WD
93--- orig/options.c 2004-07-26 16:43:48
94+++ options.c 2004-07-23 22:04:42
95@@ -114,12 +114,13 @@ int write_batch = 0;
96 int read_batch = 0;
97 int backup_dir_len = 0;
98 int backup_suffix_len;
99+int num_comp_dest = 0;
100 unsigned int backup_dir_remainder;
09add1ae
WD
101
102 char *backup_suffix = NULL;
103 char *tmpdir = NULL;
b952a177 104 char *partial_dir = NULL;
09add1ae
WD
105-char *compare_dest = NULL;
106+char *compare_dest[MAX_COMP_DEST+1];
09add1ae
WD
107 char *config_file = NULL;
108 char *shell_cmd = NULL;
109 char *log_format = NULL;
b952a177 110@@ -140,6 +141,7 @@ char *batch_name = NULL;
09add1ae
WD
111
112 static int daemon_opt; /* sets am_daemon after option error-reporting */
113 static int modify_window_set;
114+static int saw_compare_dest = 0;
115
116 /** Local address to bind. As a character string because it's
117 * interpreted by the IPv6 layer: should be a numeric IP4 or IP6
b952a177 118@@ -317,7 +319,7 @@ void usage(enum logcode F)
09add1ae
WD
119 }
120
121 enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
122- OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
123+ OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_COMPARE_DEST, OPT_LINK_DEST,
124 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
125 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT,
126 OPT_REFUSED_BASE = 9000};
b952a177 127@@ -376,8 +378,8 @@ static struct poptOption long_options[]
09add1ae
WD
128 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
129 {"timeout", 0, POPT_ARG_INT, &io_timeout, OPT_TIMEOUT, 0, 0 },
130 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
131- {"compare-dest", 0, POPT_ARG_STRING, &compare_dest, 0, 0, 0 },
132- {"link-dest", 0, POPT_ARG_STRING, &compare_dest, OPT_LINK_DEST, 0, 0 },
133+ {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
134+ {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
135 /* TODO: Should this take an optional int giving the compression level? */
136 {"compress", 'z', POPT_ARG_NONE, &do_compression, 0, 0, 0 },
137 {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 },
b952a177 138@@ -594,8 +596,36 @@ int parse_arguments(int *argc, const cha
09add1ae
WD
139 select_timeout = io_timeout;
140 break;
141
142+ case OPT_COMPARE_DEST:
143+#if HAVE_LINK
144+ if (num_comp_dest >= MAX_COMP_DEST-1) {
145+ rprintf(FERROR, "ERROR: %s\n", "too many --compare-dest args given");
146+ return 0;
147+ }
148+ arg = poptGetOptArg(pc);
149+ if (sanitize_paths)
150+ arg = alloc_sanitize_path(arg, curr_dir);
151+ compare_dest[num_comp_dest++] = (char *)arg;
152+ saw_compare_dest = 1;
153+ break;
154+#else
155+ snprintf(err_buf, sizeof err_buf,
156+ "hard links are not supported on this %s\n",
157+ am_server ? "server" : "client");
158+ rprintf(FERROR, "ERROR: %s", err_buf);
159+ return 0;
160+#endif
161+
162 case OPT_LINK_DEST:
163 #if HAVE_LINK
164+ if (num_comp_dest >= MAX_COMP_DEST-1) {
90bcf59b 165+ rprintf(FERROR, "ERROR: %s\n", "too many --link-dest args given");
09add1ae
WD
166+ return 0;
167+ }
168+ arg = poptGetOptArg(pc);
169+ if (sanitize_paths)
170+ arg = alloc_sanitize_path(arg, curr_dir);
171+ compare_dest[num_comp_dest++] = (char *)arg;
172 link_dest = 1;
173 break;
174 #else
b952a177 175@@ -693,6 +723,11 @@ int parse_arguments(int *argc, const cha
09add1ae
WD
176 exit_cleanup(RERR_SYNTAX);
177 }
178
179+ if (saw_compare_dest && link_dest) {
180+ rprintf(FINFO,
181+ "WARNING: promoting --compare-dest options to --link-dest.\n");
182+ }
183+
184 if (archive_mode) {
185 if (!files_from)
186 recurse = 1;
b952a177 187@@ -723,8 +758,6 @@ int parse_arguments(int *argc, const cha
09add1ae 188 tmpdir = alloc_sanitize_path(tmpdir, curr_dir);
b952a177
WD
189 if (partial_dir)
190 partial_dir = alloc_sanitize_path(partial_dir, curr_dir);
09add1ae
WD
191- if (compare_dest)
192- compare_dest = alloc_sanitize_path(compare_dest, curr_dir);
193 if (backup_dir)
194 backup_dir = alloc_sanitize_path(backup_dir, curr_dir);
195 if (files_from)
b952a177 196@@ -836,8 +869,8 @@ int parse_arguments(int *argc, const cha
09add1ae
WD
197 **/
198 void server_options(char **args,int *argc)
199 {
200+ static char argstr[50+MAX_COMP_DEST*2];
201 int ac = *argc;
202- static char argstr[50];
203 char *arg;
204
205 int i, x;
b952a177 206@@ -1018,13 +1051,16 @@ void server_options(char **args,int *arg
09add1ae
WD
207 args[ac++] = tmpdir;
208 }
209
210- if (compare_dest && am_sender) {
211+ if (compare_dest[0] && am_sender) {
212 /* the server only needs this option if it is not the sender,
213 * and it may be an older version that doesn't know this
214 * option, so don't send it if client is the sender.
215 */
216- args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
217- args[ac++] = compare_dest;
218+ int i;
219+ for (i = 0; i < num_comp_dest; i++) {
220+ args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
221+ args[ac++] = compare_dest[i];
222+ }
223 }
224
225 if (files_from && (!am_sender || remote_filesfrom_file)) {
b952a177
WD
226--- orig/receiver.c 2004-07-23 21:59:07
227+++ receiver.c 2004-07-23 22:05:04
228@@ -39,7 +39,6 @@ extern int cvs_exclude;
09add1ae
WD
229 extern int io_error;
230 extern char *tmpdir;
b952a177 231 extern char *partial_dir;
09add1ae 232-extern char *compare_dest;
09add1ae
WD
233 extern int make_backups;
234 extern int do_progress;
235 extern char *backup_dir;
b952a177 236--- orig/rsync.h 2004-07-27 23:23:54
824abc86 237+++ rsync.h 2004-07-03 17:33:30
09add1ae
WD
238@@ -98,6 +98,8 @@
239
240 #define MAX_ARGS 1000
241
242+#define MAX_COMP_DEST 20
243+
244 #define MPLEX_BASE 7
245
246 #define NO_EXCLUDES 0