Should always call finish_transfer() for inplace handling, just like
[rsync/rsync.git] / receiver.c
index 847d436..e50f556 100644 (file)
@@ -28,6 +28,8 @@ extern int max_delete;
 extern int csum_length;
 extern struct stats stats;
 extern int dry_run;
+extern int read_batch;
+extern int batch_gen_fd;
 extern int am_server;
 extern int relative_paths;
 extern int keep_dirlinks;
@@ -330,6 +332,7 @@ static void discard_receive_data(int f_in, OFF_T length)
  * Receiver process runs on the same host as the generator process. */
 int recv_files(int f_in, struct file_list *flist, char *local_name)
 {
+       int next_gen_i = -1;
        int fd1,fd2;
        STRUCT_STAT st;
        char *fname, fbuf[MAXPATHLEN];
@@ -355,6 +358,12 @@ int recv_files(int f_in, struct file_list *flist, char *local_name)
 
                i = read_int(f_in);
                if (i == -1) {
+                       if (read_batch) {
+                               if (next_gen_i != flist->count)
+                                       while (read_int(batch_gen_fd) != -1) {}
+                               next_gen_i = -1;
+                       }
+
                        if (phase)
                                break;
 
@@ -399,6 +408,20 @@ int recv_files(int f_in, struct file_list *flist, char *local_name)
 
                fnamecmp = fname;
 
+               if (read_batch) {
+                       while (i > next_gen_i) {
+                               next_gen_i = read_int(batch_gen_fd);
+                               if (next_gen_i == -1)
+                                       next_gen_i = flist->count;
+                       }
+                       if (i < next_gen_i) {
+                               rprintf(FINFO, "skipping update for \"%s\"\n",
+                                       fname);
+                               discard_receive_data(f_in, file->length);
+                               continue;
+                       }
+               }
+
                if (server_exclude_list.head
                    && check_exclude(&server_exclude_list, fname,
                                     S_ISDIR(file->mode)) < 0) {
@@ -521,7 +544,7 @@ int recv_files(int f_in, struct file_list *flist, char *local_name)
                        exit_cleanup(RERR_FILEIO);
                }
 
-               if (recv_ok || keep_partial)
+               if (recv_ok || keep_partial || inplace)
                        finish_transfer(fname, fnametmp, file, recv_ok);
                else
                        do_unlink(fnametmp);
@@ -529,13 +552,25 @@ int recv_files(int f_in, struct file_list *flist, char *local_name)
                cleanup_disable();
 
                if (!recv_ok) {
-                       if (csum_length == SUM_LENGTH) {
-                               rprintf(FERROR,"ERROR: file corruption in %s. File changed during transfer?\n",
-                                       full_fname(fname));
-                       } else {
+                       int msgtype = csum_length == SUM_LENGTH || read_batch ?
+                               FERROR : FINFO;
+                       if (msgtype == FERROR || verbose) {
+                               char *errstr, *redostr;
+                               char *keptstr = keep_partial || inplace ?
+                                       "retain" : "discard";
+                               if (msgtype == FERROR) {
+                                       errstr = "ERROR";
+                                       redostr = "";
+                               } else {
+                                       errstr = "WARNING";
+                                       redostr = " (will try again)";
+                               }
+                               rprintf(msgtype,
+                                       "%s: %s failed verification -- update %sed%s.\n",
+                                       errstr, fname, keptstr, redostr);
+                       }
+                       if (csum_length != SUM_LENGTH) {
                                char buf[4];
-                               if (verbose > 1)
-                                       rprintf(FINFO,"redoing %s(%d)\n",fname,i);
                                SIVAL(buf, 0, i);
                                send_msg(MSG_REDO, buf, 4);
                        }
@@ -543,8 +578,7 @@ int recv_files(int f_in, struct file_list *flist, char *local_name)
        }
        make_backups = save_make_backups;
 
-       if (delete_after && recurse && delete_mode && !local_name
-           && flist->count > 0)
+       if (delete_after && recurse && !local_name && flist->count > 0)
                delete_files(flist);
 
        if (verbose > 2)