1 Added a pipe from the generator to the receiver that communicates
2 what basis file we used to generate the file data (if it was not
3 the default name). This optimizes away the basis-file search in
4 the receiver and makes future options that do more basis-file
5 searching more efficient (such as the --fuzzy option and the
6 support for multiple --compare-dest options).
8 You must run "make proto" before compiling.
10 --- orig/generator.c 2004-07-17 15:20:05
11 +++ generator.c 2004-07-17 10:23:13
12 @@ -251,7 +251,7 @@ static void generate_and_send_sums(struc
13 * out. It might be wrong.
15 static void recv_generator(char *fname, struct file_struct *file, int i,
17 + int f_out, int f_nameout)
21 @@ -418,8 +418,10 @@ static void recv_generator(char *fname,
22 statret = link_stat(fnamecmpbuf, &st, 0);
23 if (!S_ISREG(st.st_mode))
28 + *fnamecmpbuf = '\0';
31 else if (link_dest && !dry_run) {
32 if (do_link(fnamecmpbuf, fname) != 0) {
33 @@ -427,18 +429,22 @@ static void recv_generator(char *fname,
34 rsyserr(FINFO, errno, "link %s => %s",
38 - fnamecmp = fnamecmpbuf;
39 + fnamecmp = fnamecmpbuf;
41 + *fnamecmpbuf = '\0';
45 fnamecmp = fnamecmpbuf;
48 + *fnamecmpbuf = '\0';
51 if (preserve_hard_links && hard_link_check(file, HL_SKIP))
53 if (errno == ENOENT) {
55 + write_byte(f_nameout, 0);
58 write_sum_head(f_out, NULL);
59 @@ -458,19 +464,21 @@ static void recv_generator(char *fname,
60 /* now pretend the file didn't exist */
61 if (preserve_hard_links && hard_link_check(file, HL_SKIP))
64 + write_byte(f_nameout, 0);
67 write_sum_head(f_out, NULL);
71 - if (opt_ignore_existing && fnamecmp == fname) {
72 + if (opt_ignore_existing && !*fnamecmpbuf) {
74 rprintf(FINFO,"%s exists\n",fname);
78 - if (update_only && fnamecmp == fname
79 + if (update_only && !*fnamecmpbuf
80 && cmp_modtime(st.st_mtime, file->modtime) > 0) {
82 rprintf(FINFO,"%s is newer\n",fname);
83 @@ -478,17 +486,21 @@ static void recv_generator(char *fname,
86 if (skip_file(fname, file, &st)) {
87 - if (fnamecmp == fname)
89 set_perms(fname, file, &st, PERMS_REPORT);
95 + write_byte(f_nameout, 0);
100 if (whole_file > 0) {
101 + if (f_nameout >= 0)
102 + write_byte(f_nameout, 0);
104 write_sum_head(f_out, NULL);
106 @@ -503,6 +515,8 @@ static void recv_generator(char *fname,
107 /* pretend the file didn't exist */
108 if (preserve_hard_links && hard_link_check(file, HL_SKIP))
110 + if (f_nameout >= 0)
111 + write_byte(f_nameout, 0);
113 write_sum_head(f_out, NULL);
115 @@ -521,6 +535,22 @@ static void recv_generator(char *fname,
117 rprintf(FINFO, "generating and sending sums for %d\n", i);
119 + if (f_nameout >= 0) {
120 + uchar lenbuf[3], *lb = lenbuf;
121 + int len = strlen(fnamecmpbuf);
123 +#if MAXPATHLEN > 32767
124 + *lb++ = len / 0x10000 + 0x80;
125 + *lb++ = len / 0x100;
127 + *lb++ = len / 0x100 + 0x80;
131 + write_buf(f_nameout, lenbuf, lb - lenbuf + 1);
132 + write_buf(f_nameout, fnamecmpbuf, len);
136 generate_and_send_sums(mapbuf, st.st_size, f_out);
138 @@ -530,7 +560,8 @@ static void recv_generator(char *fname,
142 -void generate_files(int f_out, struct file_list *flist, char *local_name)
143 +void generate_files(int f_out, struct file_list *flist, char *local_name,
148 @@ -571,7 +602,7 @@ void generate_files(int f_out, struct fi
151 recv_generator(local_name ? local_name : f_name_to(file, fbuf),
153 + file, i, f_out, f_nameout);
157 @@ -588,7 +619,7 @@ void generate_files(int f_out, struct fi
158 while ((i = get_redo_num()) != -1) {
159 struct file_struct *file = flist->files[i];
160 recv_generator(local_name ? local_name : f_name_to(file, fbuf),
162 + file, i, f_out, f_nameout);
166 @@ -607,7 +638,7 @@ void generate_files(int f_out, struct fi
167 if (!file->basename || !S_ISDIR(file->mode))
169 recv_generator(local_name ? local_name : f_name(file),
175 --- orig/main.c 2004-07-17 15:20:05
176 +++ main.c 2004-07-17 15:22:08
177 @@ -444,7 +444,7 @@ static int do_recv(int f_in,int f_out,st
182 + int error_pipe[2], name_pipe[2];
184 if (preserve_hard_links)
185 init_hard_links(flist);
186 @@ -456,8 +456,8 @@ static int do_recv(int f_in,int f_out,st
190 - if (fd_pair(error_pipe) < 0) {
191 - rprintf(FERROR,"error pipe failed in do_recv\n");
192 + if (fd_pair(error_pipe) < 0 || fd_pair(name_pipe) < 0) {
193 + rprintf(FERROR, "fd_pair() failed in do_recv\n");
194 exit_cleanup(RERR_SOCKETIO);
197 @@ -465,8 +465,10 @@ static int do_recv(int f_in,int f_out,st
199 if ((pid = do_fork()) == 0) {
200 close(error_pipe[0]);
201 + close(name_pipe[1]);
204 + set_blocking(name_pipe[0]);
206 /* we can't let two processes write to the socket at one time */
207 io_multiplexing_close();
208 @@ -474,7 +476,7 @@ static int do_recv(int f_in,int f_out,st
209 /* set place to send errors */
210 set_msg_fd_out(error_pipe[1]);
212 - recv_files(f_in,flist,local_name);
213 + recv_files(f_in, flist, local_name, name_pipe[0]);
214 io_flush(FULL_FLUSH);
217 @@ -492,14 +494,16 @@ static int do_recv(int f_in,int f_out,st
220 close(error_pipe[1]);
221 + close(name_pipe[0]);
224 + set_nonblocking(name_pipe[1]);
226 io_start_buffering_out();
228 set_msg_fd_in(error_pipe[0]);
230 - generate_files(f_out, flist, local_name);
231 + generate_files(f_out, flist, local_name, name_pipe[1]);
233 get_redo_num(); /* Read final MSG_DONE and any prior messages. */
235 --- orig/receiver.c 2004-07-16 20:07:22
236 +++ receiver.c 2004-07-17 11:05:36
237 @@ -304,7 +304,8 @@ static int receive_data(int f_in,struct
238 * main routine for receiver process.
240 * Receiver process runs on the same host as the generator process. */
241 -int recv_files(int f_in, struct file_list *flist, char *local_name)
242 +int recv_files(int f_in, struct file_list *flist, char *local_name,
247 @@ -317,7 +318,7 @@ int recv_files(int f_in, struct file_lis
248 struct file_struct *file;
249 struct stats initial_stats;
250 int save_make_backups = make_backups;
251 - int i, recv_ok, phase = 0;
252 + int i, len, recv_ok, phase = 0;
255 rprintf(FINFO,"recv_files(%d) starting\n",flist->count);
256 @@ -373,19 +374,25 @@ int recv_files(int f_in, struct file_lis
258 rprintf(FINFO,"recv_files(%s)\n",fname);
261 + len = read_byte(f_name);
263 +#if MAXPATHLEN > 32767
264 + read_buf(f_name, fnamecmpbuf, 2);
265 + len = (len & ~0x80) * 0x10000
266 + + fnamecmpbuf[0] * 0x100 + fnamecmpbuf[1];
268 + len = (len & ~0x80) * 0x100 + read_byte(f_name);
272 + read_sbuf(f_name, fnamecmpbuf, len);
273 + fnamecmp = fnamecmpbuf;
278 fd1 = do_open(fnamecmp, O_RDONLY, 0);
280 - if (fd1 == -1 && compare_dest != NULL) {
281 - /* try the file at compare_dest instead */
282 - pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
283 - compare_dest, fname);
284 - fnamecmp = fnamecmpbuf;
285 - fd1 = do_open(fnamecmp, O_RDONLY, 0);
288 if (fd1 != -1 && do_fstat(fd1,&st) != 0) {
289 rsyserr(FERROR, errno, "fstat %s failed",
290 full_fname(fnamecmp));