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-10-06 00:12:16
11 +++ generator.c 2004-10-09 04:06:49
12 @@ -254,14 +254,15 @@ static void generate_and_send_sums(int f
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_out_name)
20 + int fd = -1, f_copy = -1;
21 STRUCT_STAT st, partial_st;
22 - struct file_struct *back_file;
23 + struct file_struct *back_file = NULL;
24 int statret, stat_errno;
25 - char *fnamecmp, *partialptr, *backupptr;
26 + char *fnamecmp, *partialptr, *backupptr = NULL;
27 char fnamecmpbuf[MAXPATHLEN];
28 + uchar fnamecmp_type;
32 @@ -421,6 +422,7 @@ static void recv_generator(char *fname,
36 + fnamecmp_type = G2R_FNAME;
38 if (statret == -1 && compare_dest != NULL) {
39 /* try the file at compare_dest instead */
40 @@ -437,10 +439,14 @@ static void recv_generator(char *fname,
43 fnamecmp = fnamecmpbuf;
49 fnamecmp = fnamecmpbuf;
55 @@ -463,11 +469,9 @@ static void recv_generator(char *fname,
57 if (preserve_hard_links && hard_link_check(file, HL_SKIP))
59 - if (stat_errno == ENOENT) {
61 - if (!dry_run && !read_batch)
62 - write_sum_head(f_out, NULL);
63 - } else if (verbose > 1) {
64 + if (stat_errno == ENOENT)
67 rsyserr(FERROR, stat_errno,
68 "recv_generator: failed to stat %s",
70 @@ -475,13 +479,13 @@ static void recv_generator(char *fname,
74 - if (opt_ignore_existing && fnamecmp == fname) {
75 + if (opt_ignore_existing && fnamecmp_type == G2R_FNAME) {
77 rprintf(FINFO, "%s exists\n", safe_fname(fname));
81 - if (update_only && fnamecmp == fname
82 + if (update_only && fnamecmp_type == G2R_FNAME
83 && cmp_modtime(st.st_mtime, file->modtime) > 0) {
85 rprintf(FINFO, "%s is newer\n", safe_fname(fname));
86 @@ -489,26 +493,23 @@ static void recv_generator(char *fname,
89 if (skip_file(fnamecmp, file, &st)) {
90 - if (fnamecmp == fname)
91 + if (fnamecmp_type == G2R_FNAME)
92 set_perms(fname, file, &st, PERMS_REPORT);
97 - if (dry_run || read_batch) {
102 - if (whole_file > 0) {
103 - write_int(f_out,i);
104 - write_sum_head(f_out, NULL);
106 + if (dry_run || whole_file > 0) {
108 + goto notify_others;
111 + goto notify_others;
115 fnamecmp = partialptr;
116 + fnamecmp_type = G2R_PARTIAL_DIR;
120 @@ -521,9 +522,8 @@ prepare_to_open:
121 /* pretend the file didn't exist */
122 if (preserve_hard_links && hard_link_check(file, HL_SKIP))
124 - write_int(f_out,i);
125 - write_sum_head(f_out, NULL);
128 + goto notify_others;
131 if (inplace && make_backups) {
132 @@ -550,10 +550,7 @@ prepare_to_open:
140 + fnamecmp_type = G2R_BACKUP;
144 @@ -564,22 +561,38 @@ prepare_to_open:
146 rprintf(FINFO, "generating and sending sums for %d\n", i);
148 - write_int(f_out,i);
149 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
153 - set_perms(backupptr, back_file, NULL, 0);
155 - rprintf(FINFO, "backed up %s to %s\n", fname, backupptr);
158 + if (f_out_name >= 0) {
159 + write_byte(f_out_name, fnamecmp_type);
160 + io_flush(NORMAL_FLUSH); /* XXX make this more efficient! */
164 + write_int(f_out, i);
166 + if (dry_run || read_batch)
169 + if (statret == 0) {
170 + generate_and_send_sums(fd, st.st_size, f_out, f_copy);
174 + set_perms(backupptr, back_file, NULL, 0);
176 + rprintf(FINFO, "backed up %s to %s\n",
184 + write_sum_head(f_out, NULL);
188 -void generate_files(int f_out, struct file_list *flist, char *local_name)
189 +void generate_files(int f_out, struct file_list *flist, char *local_name,
194 @@ -620,7 +633,7 @@ void generate_files(int f_out, struct fi
197 recv_generator(local_name ? local_name : f_name_to(file, fbuf),
199 + file, i, f_out, f_out_name);
203 @@ -637,7 +650,7 @@ void generate_files(int f_out, struct fi
204 while ((i = get_redo_num()) != -1) {
205 struct file_struct *file = flist->files[i];
206 recv_generator(local_name ? local_name : f_name_to(file, fbuf),
208 + file, i, f_out, f_out_name);
212 @@ -656,7 +669,7 @@ void generate_files(int f_out, struct fi
213 if (!file->basename || !S_ISDIR(file->mode))
215 recv_generator(local_name ? local_name : f_name(file),
221 --- orig/main.c 2004-10-08 20:16:26
222 +++ main.c 2004-10-09 03:25:43
223 @@ -59,6 +59,7 @@ extern int filesfrom_fd;
224 extern pid_t cleanup_child_pid;
225 extern char *files_from;
226 extern char *remote_filesfrom_file;
227 +extern char *compare_dest;
228 extern char *rsync_path;
229 extern char *shell_cmd;
230 extern char *batch_name;
231 @@ -461,7 +462,8 @@ static int do_recv(int f_in,int f_out,st
236 + int error_pipe[2], name_pipe[2];
237 + BOOL need_name_pipe = compare_dest && !dry_run;
239 /* The receiving side mustn't obey this, or an existing symlink that
240 * points to an identical file won't be replaced by the referent. */
241 @@ -476,7 +478,8 @@ static int do_recv(int f_in,int f_out,st
245 - if (fd_pair(error_pipe) < 0) {
246 + if (fd_pair(error_pipe) < 0
247 + || (need_name_pipe && fd_pair(name_pipe) < 0)) {
248 rsyserr(FERROR, errno, "pipe failed in do_recv");
249 exit_cleanup(RERR_SOCKETIO);
251 @@ -485,6 +488,11 @@ static int do_recv(int f_in,int f_out,st
253 if ((pid = do_fork()) == 0) {
254 close(error_pipe[0]);
255 + if (need_name_pipe) {
256 + close(name_pipe[1]);
257 + set_blocking(name_pipe[0]);
263 @@ -494,7 +502,7 @@ static int do_recv(int f_in,int f_out,st
264 /* set place to send errors */
265 set_msg_fd_out(error_pipe[1]);
267 - recv_files(f_in,flist,local_name);
268 + recv_files(f_in, flist, local_name, name_pipe[0]);
269 io_flush(FULL_FLUSH);
272 @@ -513,6 +521,11 @@ static int do_recv(int f_in,int f_out,st
275 close(error_pipe[1]);
276 + if (need_name_pipe) {
277 + close(name_pipe[0]);
278 + set_nonblocking(name_pipe[1]);
284 @@ -520,7 +533,7 @@ static int do_recv(int f_in,int f_out,st
286 set_msg_fd_in(error_pipe[0]);
288 - generate_files(f_out, flist, local_name);
289 + generate_files(f_out, flist, local_name, name_pipe[1]);
291 get_redo_num(); /* Read final MSG_DONE and any prior messages. */
293 --- orig/receiver.c 2004-09-21 09:40:27
294 +++ receiver.c 2004-09-07 21:57:20
295 @@ -329,7 +329,8 @@ static void discard_receive_data(int f_i
296 * main routine for receiver process.
298 * Receiver process runs on the same host as the generator process. */
299 -int recv_files(int f_in, struct file_list *flist, char *local_name)
300 +int recv_files(int f_in, struct file_list *flist, char *local_name,
305 @@ -358,8 +359,13 @@ int recv_files(int f_in, struct file_lis
309 - if (next_gen_i != flist->count)
310 - while (read_int(batch_gen_fd) != -1) {}
311 + if (next_gen_i != flist->count) {
314 + && next_gen_i >= 0)
315 + read_byte(f_in_name);
316 + } while (read_int(batch_gen_fd) != -1);
321 @@ -407,6 +413,8 @@ int recv_files(int f_in, struct file_lis
324 while (i > next_gen_i) {
325 + if (f_in_name >= 0 && next_gen_i >= 0)
326 + read_byte(f_in_name);
327 next_gen_i = read_int(batch_gen_fd);
328 if (next_gen_i == -1)
329 next_gen_i = flist->count;
330 @@ -417,6 +425,7 @@ int recv_files(int f_in, struct file_lis
331 discard_receive_data(f_in, file->length);
337 if (server_exclude_list.head
338 @@ -426,35 +435,31 @@ int recv_files(int f_in, struct file_lis
339 exit_cleanup(RERR_PROTOCOL);
343 - if ((partialptr = partial_dir_fname(fname)) != NULL)
344 - fnamecmp = partialptr;
346 + partialptr = partial_dir ? partial_dir_fname(fname) : fname;
348 + if (f_in_name >= 0) {
349 + switch (read_byte(f_in_name)) {
353 + case G2R_PARTIAL_DIR:
354 + fnamecmp = partialptr ? partialptr : fname;
357 + fnamecmp = get_backup_name(fname);
360 + pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
361 + compare_dest, fname);
362 + fnamecmp = fnamecmpbuf;
366 - fnamecmp = partialptr = fname;
368 - if (inplace && make_backups) {
369 - if (!(fnamecmp = get_backup_name(fname)))
370 - fnamecmp = partialptr;
375 fd1 = do_open(fnamecmp, O_RDONLY, 0);
377 - if (fd1 == -1 && fnamecmp != fname) {
379 - fd1 = do_open(fnamecmp, O_RDONLY, 0);
382 - if (fd1 == -1 && compare_dest != NULL) {
383 - /* try the file at compare_dest instead */
384 - pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
385 - compare_dest, fname);
386 - fnamecmp = fnamecmpbuf;
387 - fd1 = do_open(fnamecmp, O_RDONLY, 0);
390 if (fd1 != -1 && do_fstat(fd1,&st) != 0) {
391 rsyserr(FERROR, errno, "fstat %s failed",
392 full_fname(fnamecmp));
393 --- orig/rsync.h 2004-10-09 03:21:56
394 +++ rsync.h 2004-09-07 21:52:22
396 #define PDIR_CREATE 1
397 #define PDIR_DELETE 0
399 +#define G2R_FNAME 0x80
400 +#define G2R_PARTIAL_DIR 0x81
401 +#define G2R_BACKUP 0x82
404 /* Log-message categories. FLOG is only used on the daemon side to
405 * output messages to the log file. */