Moved the verbose message about renaming the finished file down into
[rsync/rsync.git] / receiver.c
index 5d19148..0aeda10 100644 (file)
@@ -30,6 +30,7 @@ extern struct stats stats;
 extern int dry_run;
 extern int am_server;
 extern int relative_paths;
+extern int keep_dirlinks;
 extern int preserve_hard_links;
 extern int preserve_perms;
 extern int cvs_exclude;
@@ -59,6 +60,10 @@ static void delete_one(char *fn, int is_dir)
                }
        } else {
                if (do_rmdir(fn) != 0) {
+                       if (errno == ENOTDIR && keep_dirlinks) {
+                               delete_one(fn, 0);
+                               return;
+                       }
                        if (errno != ENOTEMPTY && errno != EEXIST) {
                                rsyserr(FERROR, errno,
                                        "delete_one: rmdir %s failed",
@@ -203,7 +208,7 @@ static int receive_data(int f_in,struct map_struct *mapbuf,int fd,char *fname,
        char *data;
        static char file_sum1[MD4_SUM_LENGTH];
        static char file_sum2[MD4_SUM_LENGTH];
-       char *map=NULL;
+       char *map = NULL;
 
        read_sum_head(f_in, &sum);
 
@@ -298,11 +303,10 @@ int recv_files(int f_in,struct file_list *flist,char *local_name)
        char *fnamecmp;
        char fnamecmpbuf[MAXPATHLEN];
        struct map_struct *mapbuf;
-       int i;
        struct file_struct *file;
-       int phase=0;
-       int recv_ok;
        struct stats initial_stats;
+       int save_make_backups = make_backups;
+       int i, recv_ok, phase = 0;
 
        if (verbose > 2) {
                rprintf(FINFO,"recv_files(%d) starting\n",flist->count);
@@ -318,15 +322,16 @@ int recv_files(int f_in,struct file_list *flist,char *local_name)
 
                i = read_int(f_in);
                if (i == -1) {
-                       if (phase == 0) {
-                               phase++;
-                               csum_length = SUM_LENGTH;
-                               if (verbose > 2)
-                                       rprintf(FINFO,"recv_files phase=%d\n",phase);
-                               send_msg(MSG_DONE, "", 0);
-                               continue;
-                       }
-                       break;
+                       if (phase)
+                               break;
+                       phase = 1;
+                       csum_length = SUM_LENGTH;
+                       if (verbose > 2)
+                               rprintf(FINFO, "recv_files phase=%d\n", phase);
+                       send_msg(MSG_DONE, "", 0);
+                       if (keep_partial)
+                               make_backups = 0; /* prevents double backup */
+                       continue;
                }
 
                if (i < 0 || i >= flist->count) {
@@ -408,8 +413,10 @@ int recv_files(int f_in,struct file_list *flist,char *local_name)
 
                if (fd1 != -1 && st.st_size > 0) {
                        mapbuf = map_file(fd1,st.st_size);
-                       if (verbose > 2)
-                               rprintf(FINFO,"recv mapped %s of size %.0f\n",fnamecmp,(double)st.st_size);
+                       if (verbose > 2) {
+                               rprintf(FINFO, "recv mapped %s of size %.0f\n",
+                                       fnamecmp, (double)st.st_size);
+                       }
                } else
                        mapbuf = NULL;
 
@@ -467,9 +474,6 @@ int recv_files(int f_in,struct file_list *flist,char *local_name)
                        exit_cleanup(RERR_FILEIO);
                }
 
-               if (verbose > 2)
-                       rprintf(FINFO,"renaming %s to %s\n",fnametmp,fname);
-
                if (recv_ok || keep_partial)
                        finish_transfer(fname, fnametmp, file, recv_ok);
                else
@@ -490,6 +494,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)