Made some more char pointers const.
[rsync/rsync.git] / receiver.c
index 9866648..ed1111a 100644 (file)
@@ -83,10 +83,10 @@ static int updating_basis;
  *   As long as it's unique, rsync will work.
  */
 
-int get_tmpname(char *fnametmp, char *fname)
+int get_tmpname(char *fnametmp, const char *fname)
 {
        int maxname, added, length = 0;
-       char *f;
+       const char *f;
 
        if (tmpdir) {
                /* Note: this can't overflow, so the return value is safe */
@@ -157,20 +157,22 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
                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 = (int32)(sum.flength - offset);
-                       if (do_progress)
-                               show_progress(offset, total_size);
-                       sum_update(map_ptr(mapbuf, offset, len), len);
-                       offset = sum.flength;
+               if (append_mode == 2) {
+                       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 = (int32)(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 && (j = do_lseek(fd, offset, SEEK_SET)) != offset) {
                        rsyserr(FERROR, errno, "lseek of %s returned %.0f, not %.0f",
                                full_fname(fname), (double)j, (double)offset);
@@ -362,8 +364,6 @@ int recv_files(int f_in, char *local_name)
        if (delay_updates)
                delayed_bits = bitbag_create(cur_flist->used + 1);
 
-       updating_basis = inplace;
-
        while (1) {
                cleanup_disable();
 
@@ -426,8 +426,9 @@ int recv_files(int f_in, char *local_name)
                        if (csum_length == SHORT_SUM_LENGTH) {
                                if (keep_partial && !partial_dir)
                                        make_backups = -make_backups; /* prevents double backup */
+                               if (append_mode)
+                                       sparse_files = -sparse_files;
                                append_mode = -append_mode;
-                               sparse_files = -sparse_files;
                                csum_length = SUM_LENGTH;
                                redoing = 1;
                        }
@@ -435,8 +436,9 @@ int recv_files(int f_in, char *local_name)
                        if (csum_length != SHORT_SUM_LENGTH) {
                                if (keep_partial && !partial_dir)
                                        make_backups = -make_backups;
+                               if (append_mode)
+                                       sparse_files = -sparse_files;
                                append_mode = -append_mode;
-                               sparse_files = -sparse_files;
                                csum_length = SHORT_SUM_LENGTH;
                                redoing = 0;
                        }
@@ -494,7 +496,6 @@ int recv_files(int f_in, char *local_name)
                                fnamecmp = get_backup_name(fname);
                                break;
                        case FNAMECMP_FUZZY:
-                               updating_basis = 0;
                                if (file->dirname) {
                                        pathjoin(fnamecmpbuf, MAXPATHLEN,
                                                 file->dirname, xname);
@@ -503,7 +504,6 @@ int recv_files(int f_in, char *local_name)
                                        fnamecmp = xname;
                                break;
                        default:
-                               updating_basis = 0;
                                if (fnamecmp_type >= basis_dir_cnt) {
                                        rprintf(FERROR,
                                                "invalid basis_dir index: %d.\n",
@@ -549,6 +549,7 @@ int recv_files(int f_in, char *local_name)
                                fd1 = do_open(fnamecmp, O_RDONLY, 0);
                        }
                }
+               updating_basis = inplace && fnamecmp == fname;
 
                if (fd1 == -1) {
                        st.st_mode = 0;