Need to make sure that the destination file doesn't exist before we
[rsync/rsync-patches.git] / compare-dest.diff
index a6e84bd..cdb9356 100644 (file)
@@ -9,73 +9,97 @@ they are suppled).
 
 Before compiling, be sure to run "make proto".
 
---- orig/generator.c   2004-07-03 20:08:07
-+++ generator.c        2004-07-03 20:14:37
-@@ -42,7 +42,7 @@ extern int size_only;
- extern int io_timeout;
+--- orig/generator.c   2004-09-20 19:57:58
++++ generator.c        2004-07-30 07:28:13
+@@ -45,7 +45,7 @@ extern int io_timeout;
  extern int protocol_version;
  extern int always_checksum;
+ extern char *partial_dir;
 -extern char *compare_dest;
 +extern char *compare_dest[];
  extern int link_dest;
  extern int whole_file;
  extern int local_server;
-@@ -80,13 +80,12 @@ static int skip_file(char *fname, struct
-       if (always_checksum && S_ISREG(st->st_mode)) {
-               char sum[MD4_SUM_LENGTH];
-               char fnamecmpdest[MAXPATHLEN];
-+              int i;
--              if (compare_dest != NULL) {
--                      if (access(fname, 0) != 0) {
--                              pathjoin(fnamecmpdest, sizeof fnamecmpdest,
--                                       compare_dest, fname);
--                              fname = fnamecmpdest;
--                      }
-+              for (i = 0; compare_dest[i] != NULL && access(fname, 0) < 0; i++) {
-+                      pathjoin(fnamecmpdest, sizeof fnamecmpdest,
-+                                      compare_dest[i], fname);
-+                      fname = fnamecmpdest;
-               }
-               file_checksum(fname,sum,st->st_size);
-               return memcmp(sum, file->u.sum, protocol_version < 21 ? 2
-@@ -411,13 +410,18 @@ static void recv_generator(char *fname, 
+@@ -426,11 +426,19 @@ static void recv_generator(char *fname, 
        fnamecmp = fname;
+       fnamecmp_type = G2R_FNAME;
  
 -      if (statret == -1 && compare_dest != NULL) {
 +      if (statret == -1 && compare_dest[0] != NULL) {
                /* try the file at compare_dest instead */
-               int saveerrno = errno;
 -              pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, compare_dest, fname);
--              statret = link_stat(fnamecmpbuf, &st, 0);
--              if (!S_ISREG(st.st_mode))
--                      statret = -1;
-+              int i;
-+              for (i = 0; compare_dest[i] != NULL; i++) {
-+                      pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, compare_dest[i], fname);
-+                      if ((statret = link_stat(fnamecmpbuf, &st, 0)) == 0) {
-+                              if (S_ISREG(st.st_mode))
-+                                      break;
-+                              statret = -1;
+-              if (link_stat(fnamecmpbuf, &st, 0) == 0
+-                  && S_ISREG(st.st_mode)) {
++              int i = 0;
++              do {
++                      pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
++                               compare_dest[i], fname);
++                      if (link_stat(fnamecmpbuf, &st, 0) == 0
++                          && S_ISREG(st.st_mode)) {
++                              statret = 0;
++                              break;
 +                      }
-+              }
-               if (statret < 0) {
-                       errno = saveerrno;
-                       *fnamecmpbuf = '\0';
---- orig/options.c     2004-07-16 20:07:22
-+++ options.c  2004-07-03 17:33:30
-@@ -118,7 +118,8 @@ unsigned int backup_dir_remainder;
++              } while (compare_dest[++i] != NULL);
++              if (statret == 0) {
+ #if HAVE_LINK
+                       if (link_dest && !dry_run) {
+                               if (do_link(fnamecmpbuf, fname) < 0) {
+@@ -441,15 +449,14 @@ static void recv_generator(char *fname, 
+                                                       safe_fname(fname));
+                                       }
+                                       fnamecmp = fnamecmpbuf;
+-                                      fnamecmp_type = 0;
++                                      fnamecmp_type = i;
+                               }
+                       } else
+ #endif
+                       {
+                               fnamecmp = fnamecmpbuf;
+-                              fnamecmp_type = 0;
++                              fnamecmp_type = i;
+                       }
+-                      statret = 0;
+               }
+       }
+--- orig/main.c        2004-07-22 00:10:43
++++ main.c     2004-07-30 07:23:54
+@@ -59,7 +59,7 @@ extern int filesfrom_fd;
+ extern pid_t cleanup_child_pid;
+ extern char *files_from;
+ extern char *remote_filesfrom_file;
+-extern char *compare_dest;
++extern char *compare_dest[];
+ extern char *rsync_path;
+ extern char *shell_cmd;
+ extern char *batch_name;
+@@ -463,7 +463,7 @@ static int do_recv(int f_in,int f_out,st
+       int pid;
+       int status = 0;
+       int error_pipe[2], name_pipe[2];
+-      BOOL need_name_pipe = compare_dest && !dry_run;
++      BOOL need_name_pipe = compare_dest[0] && !dry_run;
+       /* The receiving side mustn't obey this, or an existing symlink that
+        * points to an identical file won't be replaced by the referent. */
+--- orig/options.c     2004-09-20 05:10:48
++++ options.c  2004-08-13 07:55:37
+@@ -114,12 +114,13 @@ int write_batch = 0;
+ int read_batch = 0;
+ int backup_dir_len = 0;
+ int backup_suffix_len;
++int num_comp_dest = 0;
+ unsigned int backup_dir_remainder;
  
  char *backup_suffix = NULL;
  char *tmpdir = NULL;
+ char *partial_dir = NULL;
 -char *compare_dest = NULL;
 +char *compare_dest[MAX_COMP_DEST+1];
-+int num_comp_dest = 0;
  char *config_file = NULL;
  char *shell_cmd = NULL;
  char *log_format = NULL;
-@@ -139,6 +140,7 @@ char *batch_name = NULL;
+@@ -140,6 +141,7 @@ char *batch_name = NULL;
  
  static int daemon_opt;   /* sets am_daemon after option error-reporting */
  static int modify_window_set;
@@ -83,7 +107,7 @@ Before compiling, be sure to run "make proto".
  
  /** Local address to bind.  As a character string because it's
   * interpreted by the IPv6 layer: should be a numeric IP4 or IP6
-@@ -314,7 +316,7 @@ void usage(enum logcode F)
+@@ -317,7 +319,7 @@ void usage(enum logcode F)
  }
  
  enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
@@ -92,7 +116,7 @@ Before compiling, be sure to run "make proto".
        OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
        OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT,
        OPT_REFUSED_BASE = 9000};
-@@ -373,8 +375,8 @@ static struct poptOption long_options[] 
+@@ -376,8 +378,8 @@ static struct poptOption long_options[] 
    {"max-delete",       0,  POPT_ARG_INT,    &max_delete, 0, 0, 0 },
    {"timeout",          0,  POPT_ARG_INT,    &io_timeout, OPT_TIMEOUT, 0, 0 },
    {"temp-dir",        'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
@@ -103,29 +127,21 @@ Before compiling, be sure to run "make proto".
    /* TODO: Should this take an optional int giving the compression level? */
    {"compress",        'z', POPT_ARG_NONE,   &do_compression, 0, 0, 0 },
    {"daemon",           0,  POPT_ARG_NONE,   &daemon_opt, 0, 0, 0 },
-@@ -590,8 +592,36 @@ int parse_arguments(int *argc, const cha
+@@ -605,8 +607,28 @@ int parse_arguments(int *argc, const cha
                                select_timeout = io_timeout;
                        break;
  
 +              case OPT_COMPARE_DEST:
-+#if HAVE_LINK
 +                      if (num_comp_dest >= MAX_COMP_DEST-1) {
 +                              rprintf(FERROR, "ERROR: %s\n", "too many --compare-dest args given");
 +                              return 0;
 +                      }
 +                      arg = poptGetOptArg(pc);
 +                      if (sanitize_paths)
-+                              arg = alloc_sanitize_path(arg, curr_dir);
++                              arg = sanitize_path(NULL, arg, NULL, 0);
 +                      compare_dest[num_comp_dest++] = (char *)arg;
 +                      saw_compare_dest = 1;
 +                      break;
-+#else
-+                      snprintf(err_buf, sizeof err_buf,
-+                               "hard links are not supported on this %s\n",
-+                               am_server ? "server" : "client");
-+                      rprintf(FERROR, "ERROR: %s", err_buf);
-+                      return 0;
-+#endif
 +
                case OPT_LINK_DEST:
  #if HAVE_LINK
@@ -135,13 +151,13 @@ Before compiling, be sure to run "make proto".
 +                      }
 +                      arg = poptGetOptArg(pc);
 +                      if (sanitize_paths)
-+                              arg = alloc_sanitize_path(arg, curr_dir);
++                              arg = sanitize_path(NULL, arg, NULL, 0);
 +                      compare_dest[num_comp_dest++] = (char *)arg;
                        link_dest = 1;
                        break;
  #else
-@@ -684,6 +714,11 @@ int parse_arguments(int *argc, const cha
-               exit_cleanup(RERR_SYNTAX);
+@@ -699,6 +721,11 @@ int parse_arguments(int *argc, const cha
+               return 0;
        }
  
 +      if (saw_compare_dest && link_dest) {
@@ -152,16 +168,37 @@ Before compiling, be sure to run "make proto".
        if (archive_mode) {
                if (!files_from)
                        recurse = 1;
-@@ -712,8 +747,6 @@ int parse_arguments(int *argc, const cha
-                       (*argv)[i] = alloc_sanitize_path((*argv)[i], NULL);
-               if (tmpdir)
-                       tmpdir = alloc_sanitize_path(tmpdir, curr_dir);
+@@ -729,8 +756,6 @@ int parse_arguments(int *argc, const cha
+                       tmpdir = sanitize_path(NULL, tmpdir, NULL, 0);
+               if (partial_dir)
+                       partial_dir = sanitize_path(NULL, partial_dir, NULL, 0);
 -              if (compare_dest)
--                      compare_dest = alloc_sanitize_path(compare_dest, curr_dir);
+-                      compare_dest = sanitize_path(NULL, compare_dest, NULL, 0);
                if (backup_dir)
-                       backup_dir = alloc_sanitize_path(backup_dir, curr_dir);
+                       backup_dir = sanitize_path(NULL, backup_dir, NULL, 0);
                if (files_from)
-@@ -819,8 +852,8 @@ int parse_arguments(int *argc, const cha
+@@ -738,6 +763,7 @@ int parse_arguments(int *argc, const cha
+       }
+       if (server_exclude_list.head && !am_sender) {
+               struct exclude_list_struct *elp = &server_exclude_list;
++              int i;
+               if (tmpdir) {
+                       clean_fname(tmpdir, 1);
+                       if (check_exclude(elp, tmpdir, 1) < 0)
+@@ -748,9 +774,9 @@ int parse_arguments(int *argc, const cha
+                       if (check_exclude(elp, partial_dir, 1) < 0)
+                               goto options_rejected;
+               }
+-              if (compare_dest) {
+-                      clean_fname(compare_dest, 1);
+-                      if (check_exclude(elp, compare_dest, 1) < 0)
++              for (i = 0; i < num_comp_dest; i++) {
++                      clean_fname(compare_dest[i], 1);
++                      if (check_exclude(elp, compare_dest[i], 1) < 0)
+                               goto options_rejected;
+               }
+               if (backup_dir) {
+@@ -890,8 +916,8 @@ int parse_arguments(int *argc, const cha
   **/
  void server_options(char **args,int *argc)
  {
@@ -171,7 +208,7 @@ Before compiling, be sure to run "make proto".
        char *arg;
  
        int i, x;
-@@ -998,13 +1031,16 @@ void server_options(char **args,int *arg
+@@ -1074,13 +1100,16 @@ void server_options(char **args,int *arg
                args[ac++] = tmpdir;
        }
  
@@ -191,18 +228,38 @@ Before compiling, be sure to run "make proto".
        }
  
        if (files_from && (!am_sender || remote_filesfrom_file)) {
---- orig/receiver.c    2004-07-03 20:08:07
-+++ receiver.c 2004-07-03 20:14:37
-@@ -36,7 +36,6 @@ extern int preserve_perms;
- extern int cvs_exclude;
+--- orig/receiver.c    2004-09-07 21:57:20
++++ receiver.c 2004-07-30 07:31:12
+@@ -38,7 +38,7 @@ extern int cvs_exclude;
  extern int io_error;
  extern char *tmpdir;
+ extern char *partial_dir;
 -extern char *compare_dest;
++extern char *compare_dest[];
  extern int make_backups;
  extern int do_progress;
  extern char *backup_dir;
---- orig/rsync.h       2004-07-16 20:07:23
-+++ rsync.h    2004-07-03 17:33:30
+@@ -438,7 +438,8 @@ int recv_files(int f_in, struct file_lis
+               partialptr = partial_dir ? partial_dir_fname(fname) : fname;
+               if (f_in_name >= 0) {
+-                      switch (read_byte(f_in_name)) {
++                      uchar j;
++                      switch (j = read_byte(f_in_name)) {
+                       case G2R_FNAME:
+                               fnamecmp = fname;
+                               break;
+@@ -450,7 +451,7 @@ int recv_files(int f_in, struct file_lis
+                               break;
+                       default:
+                               pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
+-                                       compare_dest, fname);
++                                       compare_dest[j], fname);
+                               fnamecmp = fnamecmpbuf;
+                               break;
+                       }
+--- orig/rsync.h       2004-09-07 21:52:22
++++ rsync.h    2004-07-30 07:23:54
 @@ -98,6 +98,8 @@
  
  #define MAX_ARGS 1000