Need to make sure that the destination file doesn't exist before we
[rsync/rsync-patches.git] / link-by-hash.diff
index a8b923f..49bcf6b 100644 (file)
@@ -22,9 +22,9 @@ the file's name.
  DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
  popt_OBJS=popt/findme.o  popt/popt.o  popt/poptconfig.o \
        popt/popthelp.o popt/poptparse.o
---- orig/hashlink.c    2004-08-13 18:04:59
-+++ hashlink.c 2004-08-13 18:04:59
-@@ -0,0 +1,342 @@
+--- orig/hashlink.c    2004-09-24 16:44:25
++++ hashlink.c 2004-09-24 16:44:25
+@@ -0,0 +1,340 @@
 +/*
 +   Copyright (C) Cronosys, LLC 2004
 +
@@ -111,7 +111,7 @@ the file's name.
 +      long this_fnbr;
 +
 +      *fnbr = 0;
-+      
++
 +      /* Build a list of potential candidates and open
 +       * them. */
 +      if ((d = opendir(hashname)) == NULL) {
@@ -210,7 +210,6 @@ the file's name.
 +                      /* There are no matches. */
 +                      return NULL;
 +              }
-+              
 +      }
 +
 +      if (amt == -1) {
@@ -250,7 +249,7 @@ the file's name.
 +int link_by_hash(char *fnametmp,char *fname,struct file_struct *file)
 +{
 +      STRUCT_STAT st;
-+      char *hashname = make_hash_name(file);          
++      char *hashname = make_hash_name(file);
 +      int first = 0, rc;
 +      char *linkname;
 +      long last_fnbr;
@@ -282,10 +281,8 @@ the file's name.
 +              first = 1;
 +              asprintf(&linkname,"%s/0",hashname);
 +              rprintf(FINFO, "(1) linkname = %s\n", linkname);
-+                      
 +      } else {
 +              struct hashfile_struct *hashfiles, *hashfile;
-+              int fd;
 +
 +              if (do_stat(fnametmp,&st) == -1) {
 +                      rsyserr(FERROR, errno, "stat failed: %s", fname);
@@ -298,7 +295,7 @@ the file's name.
 +                      asprintf(&linkname,"%s/0",hashname);
 +                      rprintf(FINFO, "(2) linkname = %s\n", linkname);
 +              } else {
-+                      
++                      int fd;
 +                      /* Search for one identical to us. */
 +                      if ((fd = open(fnametmp,O_RDONLY|O_BINARY)) == -1) {
 +                              rsyserr(FERROR, errno, "open failed: %s", fnametmp);
@@ -307,6 +304,7 @@ the file's name.
 +                      }
 +                      hashfile = compare_hashfiles(fd, hashfiles);
 +                      hashfiles = NULL;
++                      close(fd);
 +
 +                      if (hashfile) {
 +                              first = 0;
@@ -325,6 +323,7 @@ the file's name.
 +      if (!first) {
 +              rprintf(FINFO, "link-by-hash (existing): \"%s\" -> %s\n",
 +                              linkname, full_fname(fname));
++              robust_unlink(fname);
 +              rc = do_link(linkname, fname);
 +              if (rc == -1) {
 +                      if (errno == EMLINK) {
@@ -337,7 +336,6 @@ the file's name.
 +                      } else {
 +                              rsyserr(FERROR, errno, "link \"%s\" -> \"%s\"",
 +                                      linkname, full_fname(fname));
-+                              robust_unlink(fname);
 +                              rc = robust_rename(fnametmp,fname,0644);
 +                      }
 +              } else {
@@ -367,7 +365,7 @@ the file's name.
 +}
 +
 +#endif
---- orig/options.c     2004-08-12 18:34:38
+--- orig/options.c     2004-09-23 17:42:07
 +++ options.c  2004-08-13 18:13:18
 @@ -126,6 +126,7 @@ char *log_format = NULL;
  char *password_file = NULL;
@@ -402,7 +400,7 @@ the file's name.
    /* 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 },
-@@ -620,6 +623,22 @@ int parse_arguments(int *argc, const cha
+@@ -616,6 +619,21 @@ int parse_arguments(int *argc, const cha
                        return 0;
  #endif
  
@@ -412,7 +410,6 @@ the file's name.
 +                      if (sanitize_paths)
 +                              arg = sanitize_path(NULL, arg, NULL, 0);
 +                      link_by_hash_dir = (char *)arg;
-+                      checksum_seed = 12345;
 +                      break;
 +#else
 +                      snprintf(err_buf, sizeof err_buf,
@@ -425,7 +422,7 @@ the file's name.
                default:
                        /* A large opt value means that set_refuse_options()
                         * turned this option off (opt-BASE is its index). */
-@@ -1078,6 +1097,11 @@ void server_options(char **args,int *arg
+@@ -1087,6 +1105,11 @@ void server_options(char **args,int *arg
                args[ac++] = compare_dest;
        }
  
@@ -437,7 +434,7 @@ the file's name.
        if (files_from && (!am_sender || remote_filesfrom_file)) {
                if (remote_filesfrom_file) {
                        args[ac++] = "--files-from";
---- orig/receiver.c    2004-08-03 15:34:32
+--- orig/receiver.c    2004-09-21 09:40:27
 +++ receiver.c 2004-07-20 21:44:05
 @@ -39,6 +39,7 @@ extern int io_error;
  extern char *tmpdir;
@@ -447,7 +444,7 @@ the file's name.
  extern int make_backups;
  extern int do_progress;
  extern char *backup_dir;
-@@ -206,12 +207,13 @@ static int get_tmpname(char *fnametmp, c
+@@ -202,12 +203,13 @@ static int get_tmpname(char *fnametmp, c
  
  
  static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
@@ -462,7 +459,7 @@ the file's name.
        unsigned int len;
        OFF_T offset = 0;
        OFF_T offset2;
-@@ -231,6 +233,9 @@ static int receive_data(int f_in, char *
+@@ -227,6 +229,9 @@ static int receive_data(int f_in, char *
        } else
                mapbuf = NULL;
  
@@ -472,7 +469,7 @@ the file's name.
        sum_init(checksum_seed);
  
        while ((i = recv_token(f_in, &data)) != 0) {
-@@ -247,6 +252,8 @@ static int receive_data(int f_in, char *
+@@ -243,6 +248,8 @@ static int receive_data(int f_in, char *
                        cleanup_got_literal = 1;
  
                        sum_update(data,i);
@@ -481,7 +478,7 @@ the file's name.
  
                        if (fd != -1 && write_file(fd,data,i) != i)
                                goto report_write_error;
-@@ -271,6 +278,8 @@ static int receive_data(int f_in, char *
+@@ -267,6 +274,8 @@ static int receive_data(int f_in, char *
  
                        see_token(map, len);
                        sum_update(map,len);
@@ -490,7 +487,7 @@ the file's name.
                }
  
                if (inplace) {
-@@ -310,6 +319,8 @@ static int receive_data(int f_in, char *
+@@ -306,6 +315,8 @@ static int receive_data(int f_in, char *
        }
  
        sum_end(file_sum1);
@@ -499,7 +496,7 @@ the file's name.
  
        if (mapbuf)
                unmap_file(mapbuf);
-@@ -325,7 +336,7 @@ static int receive_data(int f_in, char *
+@@ -321,7 +332,7 @@ static int receive_data(int f_in, char *
  
  static void discard_receive_data(int f_in, OFF_T length)
  {
@@ -508,7 +505,7 @@ the file's name.
  }
  
  
-@@ -541,8 +552,12 @@ int recv_files(int f_in, struct file_lis
+@@ -542,8 +553,12 @@ int recv_files(int f_in, struct file_lis
                        rprintf(FINFO, "%s\n", safe_fname(fname));
  
                /* recv file data */
@@ -522,7 +519,7 @@ the file's name.
  
                log_recv(file, &initial_stats);
  
---- orig/rsync.c       2004-08-09 21:07:10
+--- orig/rsync.c       2004-09-07 21:45:30
 +++ rsync.c    2004-08-13 18:14:34
 @@ -34,6 +34,7 @@ extern int force_delete;
  extern int recurse;
@@ -546,9 +543,9 @@ the file's name.
        if (ret < 0) {
                rsyserr(FERROR, errno, "%s %s -> \"%s\"",
                    ret == -2 ? "copy" : "rename",
---- orig/rsync.h       2004-08-03 15:41:32
+--- orig/rsync.h       2004-09-22 08:47:31
 +++ rsync.h    2004-07-03 20:20:15
-@@ -525,6 +525,14 @@ struct stats {
+@@ -526,6 +526,14 @@ struct stats {
        int current_file_index;
  };