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-15 02:21:10
11 +++ generator.c 2004-07-03 20:08:07
12 @@ -248,7 +248,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 @@ -415,8 +415,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 @@ -424,18 +426,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(f_nameout, "", 1);
58 write_sum_head(f_out, NULL);
59 @@ -455,19 +461,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(f_nameout, "", 1);
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 @@ -475,17 +483,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(f_nameout, "", 1);
100 if (whole_file > 0) {
101 + if (f_nameout >= 0)
102 + write(f_nameout, "", 1);
104 write_sum_head(f_out, NULL);
106 @@ -500,6 +512,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(f_nameout, "", 1);
113 write_sum_head(f_out, NULL);
115 @@ -518,6 +532,8 @@ static void recv_generator(char *fname,
117 rprintf(FINFO, "generating and sending sums for %d\n", i);
119 + if (f_nameout >= 0)
120 + write(f_nameout, fnamecmpbuf, strlen(fnamecmpbuf) + 1);
122 generate_and_send_sums(mapbuf, st.st_size, f_out);
124 @@ -527,7 +543,8 @@ static void recv_generator(char *fname,
128 -void generate_files(int f_out, struct file_list *flist, char *local_name)
129 +void generate_files(int f_out, struct file_list *flist, char *local_name,
134 @@ -568,7 +585,7 @@ void generate_files(int f_out, struct fi
137 recv_generator(local_name ? local_name : f_name_to(file, fbuf),
139 + file, i, f_out, f_nameout);
143 @@ -585,7 +602,7 @@ void generate_files(int f_out, struct fi
144 while ((i = get_redo_num()) != -1) {
145 struct file_struct *file = flist->files[i];
146 recv_generator(local_name ? local_name : f_name_to(file, fbuf),
148 + file, i, f_out, f_nameout);
152 @@ -604,7 +621,7 @@ void generate_files(int f_out, struct fi
153 if (!file->basename || !S_ISDIR(file->mode))
155 recv_generator(local_name ? local_name : f_name(file),
161 --- orig/main.c 2004-07-15 17:02:03
162 +++ main.c 2004-07-03 20:08:07
163 @@ -443,7 +443,7 @@ static int do_recv(int f_in,int f_out,st
168 + int error_pipe[2], name_pipe[2];
170 if (preserve_hard_links)
171 init_hard_links(flist);
172 @@ -455,8 +455,8 @@ static int do_recv(int f_in,int f_out,st
176 - if (fd_pair(error_pipe) < 0) {
177 - rprintf(FERROR,"error pipe failed in do_recv\n");
178 + if (fd_pair(error_pipe) < 0 || fd_pair(name_pipe) < 0) {
179 + rprintf(FERROR, "fd_pair() failed in do_recv\n");
180 exit_cleanup(RERR_SOCKETIO);
183 @@ -464,8 +464,10 @@ static int do_recv(int f_in,int f_out,st
185 if ((pid = do_fork()) == 0) {
186 close(error_pipe[0]);
187 + close(name_pipe[1]);
190 + set_blocking(name_pipe[0]);
192 /* we can't let two processes write to the socket at one time */
193 io_multiplexing_close();
194 @@ -473,7 +475,7 @@ static int do_recv(int f_in,int f_out,st
195 /* set place to send errors */
196 set_msg_fd_out(error_pipe[1]);
198 - recv_files(f_in,flist,local_name);
199 + recv_files(f_in, flist, local_name, name_pipe[0]);
200 io_flush(FULL_FLUSH);
203 @@ -491,14 +493,16 @@ static int do_recv(int f_in,int f_out,st
206 close(error_pipe[1]);
207 + close(name_pipe[0]);
210 + set_blocking(name_pipe[1]);
212 io_start_buffering_out(f_out);
214 set_msg_fd_in(error_pipe[0]);
216 - generate_files(f_out, flist, local_name);
217 + generate_files(f_out, flist, local_name, name_pipe[1]);
219 get_redo_num(); /* Read final MSG_DONE and any prior messages. */
221 --- orig/receiver.c 2004-07-14 17:12:06
222 +++ receiver.c 2004-07-03 20:08:07
223 @@ -289,14 +289,15 @@ static int receive_data(int f_in,struct
224 * main routine for receiver process.
226 * Receiver process runs on the same host as the generator process. */
227 -int recv_files(int f_in, struct file_list *flist, char *local_name)
228 +int recv_files(int f_in, struct file_list *flist, char *local_name,
233 char *fname, fbuf[MAXPATHLEN];
234 char template[MAXPATHLEN];
235 char fnametmp[MAXPATHLEN];
237 + char *fnamecmp, *cp;
238 char fnamecmpbuf[MAXPATHLEN];
239 struct map_struct *mapbuf;
240 struct file_struct *file;
241 @@ -358,19 +359,19 @@ int recv_files(int f_in, struct file_lis
243 rprintf(FINFO,"recv_files(%s)\n",fname);
246 + for (cp = fnamecmpbuf; ; cp++) {
247 + if (read(f_name, cp, 1) <= 0) {
248 + rsyserr(FERROR, errno, "fname-pipe read failed");
249 + exit_cleanup(RERR_PROTOCOL);
254 + fnamecmp = *fnamecmpbuf ? fnamecmpbuf : fname;
257 fd1 = do_open(fnamecmp, O_RDONLY, 0);
259 - if (fd1 == -1 && compare_dest != NULL) {
260 - /* try the file at compare_dest instead */
261 - pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
262 - compare_dest, fname);
263 - fnamecmp = fnamecmpbuf;
264 - fd1 = do_open(fnamecmp, O_RDONLY, 0);
267 if (fd1 != -1 && do_fstat(fd1,&st) != 0) {
268 rsyserr(FERROR, errno, "fstat %s failed",
269 full_fname(fnamecmp));
270 @@ -379,7 +380,7 @@ int recv_files(int f_in, struct file_lis
274 - if (fd1 != -1 && S_ISDIR(st.st_mode) && fnamecmp == fname) {
275 + if (fd1 != -1 && S_ISDIR(st.st_mode) && !*fnamecmpbuf) {
276 /* this special handling for directories
277 * wouldn't be necessary if robust_rename()
278 * and the underlying robust_unlink could cope