Mention some chanages in the patches dir.
[rsync/rsync.git] / receiver.c
index 6e2bd1c..5a88311 100644 (file)
@@ -45,6 +45,8 @@ extern int remove_sent_files;
 extern int module_id;
 extern int ignore_errors;
 extern int orig_umask;
+extern int append_mode;
+extern int sparse_files;
 extern int keep_partial;
 extern int checksum_seed;
 extern int inplace;
@@ -212,6 +214,32 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
 
        sum_init(checksum_seed);
 
+       if (append_mode) {
+               OFF_T j;
+               sum.flength = (OFF_T)sum.count * sum.blength;
+               if (sum.remainder)
+                       sum.flength -= sum.blength - sum.remainder;
+               for (j = CHUNK_SIZE; j < sum.flength; j += CHUNK_SIZE) {
+                       if (do_progress)
+                               show_progress(offset, total_size);
+                       sum_update(map_ptr(mapbuf, offset, CHUNK_SIZE),
+                                  CHUNK_SIZE);
+                       offset = j;
+               }
+               if (offset < sum.flength) {
+                       int32 len = sum.flength - offset;
+                       if (do_progress)
+                               show_progress(offset, total_size);
+                       sum_update(map_ptr(mapbuf, offset, len), len);
+                       offset = sum.flength;
+               }
+               if (fd != -1 && do_lseek(fd, offset, SEEK_SET) != offset) {
+                       rsyserr(FERROR, errno, "lseek failed on %s",
+                               full_fname(fname));
+                       exit_cleanup(RERR_FILEIO);
+               }
+       }
+
        while ((i = recv_token(f_in, &data)) != 0) {
                if (do_progress)
                        show_progress(offset, total_size);
@@ -326,6 +354,8 @@ static void handle_delayed_updates(struct file_list *flist, char *local_name)
                                        safe_fname(partialptr),
                                        safe_fname(fname));
                        }
+                       /* We don't use robust_rename() here because the
+                        * partial-dir must be on the same drive. */
                        if (do_rename(partialptr, fname) < 0) {
                                rsyserr(FERROR, errno,
                                        "rename failed for %s (from %s)",
@@ -417,6 +447,10 @@ int recv_files(int f_in, struct file_list *flist, char *local_name)
                        send_msg(MSG_DONE, "", 0);
                        if (keep_partial && !partial_dir)
                                make_backups = 0; /* prevents double backup */
+                       if (append_mode) {
+                               append_mode = 0;
+                               sparse_files = 0;
+                       }
                        continue;
                }
 
@@ -462,7 +496,8 @@ int recv_files(int f_in, struct file_list *flist, char *local_name)
                }
                if (write_batch < 0) {
                        log_item(file, &stats, iflags, NULL);
-                       discard_receive_data(f_in, file->length);
+                       if (!am_server)
+                               discard_receive_data(f_in, file->length);
                        continue;
                }
 
@@ -580,7 +615,7 @@ int recv_files(int f_in, struct file_list *flist, char *local_name)
 
                /* We now check to see if we are writing file "inplace" */
                if (inplace)  {
-                       fd2 = do_open(fname, O_WRONLY|O_CREAT, 0);
+                       fd2 = do_open(fname, O_WRONLY|O_CREAT, 0600);
                        if (fd2 == -1) {
                                rsyserr(FERROR, errno, "open %s failed",
                                        full_fname(fname));