Reduced the transmitted data on the generator-to-receiver pipe down
[rsync/rsync-patches.git] / g2r-basis-filename.diff
index 2f08b03..f5e1aa2 100644 (file)
@@ -8,8 +8,8 @@ support for multiple --compare-dest options).
 You must run "make proto" before compiling.
 
 --- orig/generator.c   2004-07-29 16:49:44
-+++ generator.c        2004-07-28 10:14:15
-@@ -250,9 +250,9 @@ static void generate_and_send_sums(int f
++++ generator.c        2004-07-30 07:18:03
+@@ -250,13 +250,13 @@ static void generate_and_send_sums(int f
   * out.  It might be wrong.
   */
  static void recv_generator(char *fname, struct file_struct *file, int i,
@@ -20,28 +20,37 @@ You must run "make proto" before compiling.
 +      int fd = -1;
        STRUCT_STAT st;
        int statret, stat_errno;
-       char *fnamecmp;
-@@ -428,13 +428,16 @@ static void recv_generator(char *fname, 
+-      char *fnamecmp;
+-      char fnamecmpbuf[MAXPATHLEN];
++      char *fnamecmp, fnamecmpbuf[MAXPATHLEN];
++      uchar fnamecmp_type;
+       if (list_only)
+               return;
+@@ -412,6 +412,7 @@ static void recv_generator(char *fname, 
+       }
+       fnamecmp = fname;
++      fnamecmp_type = G2R_FNAME;
+       if (statret == -1 && compare_dest != NULL) {
+               /* try the file at compare_dest instead */
+@@ -428,10 +429,14 @@ static void recv_generator(char *fname, 
                                                        safe_fname(fname));
                                        }
                                        fnamecmp = fnamecmpbuf;
--                              }
-+                              } else
-+                                      *fnamecmpbuf = '\0';
++                                      fnamecmp_type = 0;
+                               }
                        } else
  #endif
++                      {
                                fnamecmp = fnamecmpbuf;
++                              fnamecmp_type = 0;
++                      }
                        statret = 0;
--              }
--      }
-+              } else
-+                      *fnamecmpbuf = '\0';
-+      } else
-+              *fnamecmpbuf = '\0';
-       if (statret == 0 && !S_ISREG(st.st_mode)) {
-               if (delete_file(fname) != 0)
-@@ -446,11 +449,9 @@ static void recv_generator(char *fname, 
+               }
+       }
+@@ -446,11 +451,9 @@ static void recv_generator(char *fname, 
        if (statret == -1) {
                if (preserve_hard_links && hard_link_check(file, HL_SKIP))
                        return;
@@ -56,28 +65,28 @@ You must run "make proto" before compiling.
                        rsyserr(FERROR, stat_errno,
                                "recv_generator: failed to stat %s",
                                full_fname(fname));
-@@ -458,13 +459,13 @@ static void recv_generator(char *fname, 
+@@ -458,13 +461,13 @@ static void recv_generator(char *fname, 
                return;
        }
  
 -      if (opt_ignore_existing && fnamecmp == fname) {
-+      if (opt_ignore_existing && !*fnamecmpbuf) {
++      if (opt_ignore_existing && fnamecmp_type == G2R_FNAME) {
                if (verbose > 1)
                        rprintf(FINFO, "%s exists\n", safe_fname(fname));
                return;
        }
  
 -      if (update_only && fnamecmp == fname
-+      if (update_only && !*fnamecmpbuf
++      if (update_only && fnamecmp_type == G2R_FNAME
            && cmp_modtime(st.st_mtime, file->modtime) > 0) {
                if (verbose > 1)
                        rprintf(FINFO, "%s is newer\n", safe_fname(fname));
-@@ -472,21 +473,17 @@ static void recv_generator(char *fname, 
+@@ -472,21 +475,17 @@ static void recv_generator(char *fname, 
        }
  
        if (skip_file(fnamecmp, file, &st)) {
 -              if (fnamecmp == fname)
-+              if (!*fnamecmpbuf)
++              if (fnamecmp_type == G2R_FNAME)
                        set_perms(fname, file, &st, PERMS_REPORT);
                return;
        }
@@ -100,7 +109,15 @@ You must run "make proto" before compiling.
  
        if (partial_dir) {
                STRUCT_STAT st2;
-@@ -507,9 +504,8 @@ static void recv_generator(char *fname, 
+@@ -495,6 +494,7 @@ static void recv_generator(char *fname, 
+                   && S_ISREG(st2.st_mode)) {
+                       st = st2;
+                       fnamecmp = partialptr;
++                      fnamecmp_type = G2R_PARTIAL_DIR;
+               }
+       }
+@@ -507,9 +507,8 @@ static void recv_generator(char *fname, 
                /* pretend the file didn't exist */
                if (preserve_hard_links && hard_link_check(file, HL_SKIP))
                        return;
@@ -112,7 +129,7 @@ You must run "make proto" before compiling.
        }
  
        if (verbose > 3) {
-@@ -520,14 +516,41 @@ static void recv_generator(char *fname, 
+@@ -520,14 +519,28 @@ static void recv_generator(char *fname, 
        if (verbose > 2)
                rprintf(FINFO, "generating and sending sums for %d\n", i);
  
@@ -120,29 +137,16 @@ You must run "make proto" before compiling.
 -      generate_and_send_sums(fd, st.st_size, f_out);
 +notify_others:
 +      if (f_out_name >= 0) {
-+              uchar lenbuf[3], *lb = lenbuf;
-+              int len = statret == -1 ? 0 : strlen(fnamecmpbuf);
-+              if (len > 0x7F) {
-+#if MAXPATHLEN > 0x7FFF
-+                      *lb++ = len / 0x10000 + 0x80;
-+                      *lb++ = len / 0x100;
-+#else
-+                      *lb++ = len / 0x100 + 0x80;
-+#endif
-+              }
-+              *lb = len;
-+              write_buf(f_out_name, lenbuf, lb - lenbuf + 1);
-+              if (len)
-+                      write_buf(f_out_name, fnamecmpbuf, len);
++              write_byte(f_out_name, fnamecmp_type);
 +              io_flush(NORMAL_FLUSH); /* XXX make this more efficient! */
 +      }
 +
 +      write_int(f_out, i);
-+
-+      if (dry_run || read_batch)
-+              return;
  
 -      close(fd);
++      if (dry_run || read_batch)
++              return;
++
 +      if (statret == 0) {
 +              generate_and_send_sums(fd, st.st_size, f_out);
 +
@@ -158,7 +162,7 @@ You must run "make proto" before compiling.
  {
        int i;
        int phase = 0;
-@@ -568,7 +591,7 @@ void generate_files(int f_out, struct fi
+@@ -568,7 +581,7 @@ void generate_files(int f_out, struct fi
                }
  
                recv_generator(local_name ? local_name : f_name_to(file, fbuf),
@@ -167,7 +171,7 @@ You must run "make proto" before compiling.
        }
  
        phase++;
-@@ -585,7 +608,7 @@ void generate_files(int f_out, struct fi
+@@ -585,7 +598,7 @@ void generate_files(int f_out, struct fi
        while ((i = get_redo_num()) != -1) {
                struct file_struct *file = flist->files[i];
                recv_generator(local_name ? local_name : f_name_to(file, fbuf),
@@ -176,7 +180,7 @@ You must run "make proto" before compiling.
        }
  
        phase++;
-@@ -604,7 +627,7 @@ void generate_files(int f_out, struct fi
+@@ -604,7 +617,7 @@ void generate_files(int f_out, struct fi
                if (!file->basename || !S_ISDIR(file->mode))
                        continue;
                recv_generator(local_name ? local_name : f_name(file),
@@ -259,40 +263,9 @@ You must run "make proto" before compiling.
  
        get_redo_num(); /* Read final MSG_DONE and any prior messages. */
        report(-1);
---- orig/receiver.c    2004-07-29 16:08:03
-+++ receiver.c 2004-07-23 21:59:07
-@@ -323,6 +323,30 @@ static int receive_data(int f_in, char *
- }
-+static char *read_gen_name(int fd, char *buf, char *realname)
-+{
-+      int len = read_byte(fd);
-+      if (len & 0x80) {
-+#if MAXPATHLEN > 32767
-+              uchar lenbuf[2];
-+              read_buf(fd, (char *)lenbuf, 2);
-+              len = (len & ~0x80) * 0x10000 + lenbuf[0] * 0x100 + lenbuf[1];
-+#else
-+              len = (len & ~0x80) * 0x100 + read_byte(fd);
-+#endif
-+      }
-+      if (len) {
-+              if (len >= MAXPATHLEN) {
-+                      rprintf(FERROR, "bogus data on generator name pipe\n");
-+                      exit_cleanup(RERR_PROTOCOL);
-+              }
-+              read_sbuf(fd, buf, len);
-+              return buf;
-+      }
-+      return realname;
-+}
-+
-+
- static void discard_receive_data(int f_in, OFF_T length)
- {
-       receive_data(f_in, NULL, -1, 0, NULL, -1, length);
-@@ -333,7 +357,8 @@ static void discard_receive_data(int f_i
+--- orig/receiver.c    2004-07-30 07:04:00
++++ receiver.c 2004-07-30 07:17:48
+@@ -333,7 +333,8 @@ static void discard_receive_data(int f_i
   * main routine for receiver process.
   *
   * Receiver process runs on the same host as the generator process. */
@@ -302,69 +275,75 @@ You must run "make proto" before compiling.
  {
        int next_gen_i = -1;
        int fd1,fd2;
-@@ -362,8 +387,15 @@ int recv_files(int f_in, struct file_lis
+@@ -362,8 +363,13 @@ int recv_files(int f_in, struct file_lis
                i = read_int(f_in);
                if (i == -1) {
                        if (read_batch) {
 -                              if (next_gen_i != flist->count)
 -                                      while (read_int(batch_gen_fd) != -1) {}
-+                              while (next_gen_i < flist->count) {
-+                                      if (f_in_name >= 0 && next_gen_i >= 0) {
-+                                              read_gen_name(f_in_name,
-+                                                      fnamecmpbuf, NULL);
-+                                      }
-+                                      next_gen_i = read_int(batch_gen_fd);
-+                                      if (next_gen_i < 0)
-+                                              break;
++                              if (next_gen_i != flist->count) {
++                                      do {
++                                              if (f_in_name >= 0
++                                                  && next_gen_i >= 0)
++                                                      read_byte(f_in_name);
++                                      } while (read_int(batch_gen_fd) != -1);
 +                              }
                                next_gen_i = -1;
                        }
  
-@@ -411,6 +443,10 @@ int recv_files(int f_in, struct file_lis
+@@ -411,6 +417,8 @@ int recv_files(int f_in, struct file_lis
  
                if (read_batch) {
                        while (i > next_gen_i) {
-+                              if (f_in_name >= 0 && next_gen_i >= 0) {
-+                                      read_gen_name(f_in_name, fnamecmpbuf,
-+                                                    NULL);
-+                              }
++                              if (f_in_name >= 0 && next_gen_i >= 0)
++                                      read_byte(f_in_name);
                                next_gen_i = read_int(batch_gen_fd);
                                if (next_gen_i == -1)
                                        next_gen_i = flist->count;
-@@ -421,8 +457,14 @@ int recv_files(int f_in, struct file_lis
+@@ -421,6 +429,7 @@ int recv_files(int f_in, struct file_lis
                                discard_receive_data(f_in, file->length);
                                continue;
                        }
 +                      next_gen_i = -1;
                }
  
-+              if (f_in_name >= 0)
-+                      fnamecmp = read_gen_name(f_in_name, fnamecmpbuf, fname);
-+              else
-+                      fnamecmp = fname;
-+
                if (server_exclude_list.head
-                   && check_exclude(&server_exclude_list, fname,
-                                    S_ISDIR(file->mode)) < 0) {
-@@ -435,13 +477,7 @@ int recv_files(int f_in, struct file_lis
-                       continue;
+@@ -430,30 +439,28 @@ int recv_files(int f_in, struct file_lis
+                       exit_cleanup(RERR_PROTOCOL);
                }
  
 -              if (partial_dir) {
 -                      if ((partialptr = partial_dir_fname(fname)) != NULL)
 -                              fnamecmp = partialptr;
 -                      else
--                              fnamecmp = fname;
--              } else
--                      fnamecmp = partialptr = fname;
 +              partialptr = partial_dir ? partial_dir_fname(fname) : fname;
++
++              if (f_in_name >= 0) {
++                      switch (read_byte(f_in_name)) {
++                      case G2R_FNAME:
+                               fnamecmp = fname;
++                              break;
++                      case G2R_PARTIAL_DIR:
++                              fnamecmp = partialptr ? partialptr : fname;
++                              break;
++                      default:
++                              pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
++                                       compare_dest, fname);
++                              fnamecmp = fnamecmpbuf;
++                              break;
++                      }
+               } else
+-                      fnamecmp = partialptr = fname;
++                      fnamecmp = fname;
  
                /* open the file */
                fd1 = do_open(fnamecmp, O_RDONLY, 0);
-@@ -451,14 +487,6 @@ int recv_files(int f_in, struct file_lis
-                       fd1 = do_open(fnamecmp, O_RDONLY, 0);
-               }
  
+-              if (fd1 == -1 && fnamecmp != fname) {
+-                      fnamecmp = fname;
+-                      fd1 = do_open(fnamecmp, O_RDONLY, 0);
+-              }
+-
 -              if (fd1 == -1 && compare_dest != NULL) {
 -                      /* try the file at compare_dest instead */
 -                      pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
@@ -376,3 +355,15 @@ You must run "make proto" before compiling.
                if (fd1 != -1 && do_fstat(fd1,&st) != 0) {
                        rsyserr(FERROR, errno, "fstat %s failed",
                                full_fname(fnamecmp));
+--- orig/rsync.h       2004-07-29 16:08:03
++++ rsync.h    2004-07-30 07:16:38
+@@ -118,6 +118,9 @@
+ #define PDIR_CREATE   1
+ #define PDIR_DELETE   0
++#define G2R_FNAME     0x80
++#define G2R_PARTIAL_DIR       0x81
++
+ /* Log-message categories.  FLOG is only used on the daemon side to
+  * output messages to the log file. */