If we're making backups with --inplace, use the backup file as the
[rsync/rsync.git] / generator.c
index 9c78e64..6d1f349 100644 (file)
@@ -252,9 +252,9 @@ static void recv_generator(char *fname, struct file_struct *file, int i,
                           int f_out)
 {
        int fd;
-       STRUCT_STAT st;
+       STRUCT_STAT st, partial_st;
        int statret, stat_errno;
-       char *fnamecmp;
+       char *fnamecmp, *partialptr;
        char fnamecmpbuf[MAXPATHLEN];
 
        if (list_only)
@@ -273,8 +273,14 @@ static void recv_generator(char *fname, struct file_struct *file, int i,
                return;
        }
 
-       statret = link_stat(fname, &st, keep_dirlinks && S_ISDIR(file->mode));
-       stat_errno = errno;
+       if (dry_run > 1) {
+               statret = -1;
+               stat_errno = ENOENT;
+       } else {
+               statret = link_stat(fname, &st,
+                                   keep_dirlinks && S_ISDIR(file->mode));
+               stat_errno = errno;
+       }
 
        if (only_existing && statret == -1 && stat_errno == ENOENT) {
                /* we only want to update existing files */
@@ -442,6 +448,14 @@ static void recv_generator(char *fname, struct file_struct *file, int i,
                stat_errno = ENOENT;
        }
 
+       if (partial_dir && (partialptr = partial_dir_fname(fname))
+           && link_stat(partialptr, &partial_st, 0) == 0
+           && S_ISREG(partial_st.st_mode)) {
+               if (statret == -1)
+                       goto prepare_to_open;
+       } else
+               partialptr = NULL;
+
        if (statret == -1) {
                if (preserve_hard_links && hard_link_check(file, HL_SKIP))
                        return;
@@ -476,6 +490,7 @@ static void recv_generator(char *fname, struct file_struct *file, int i,
                return;
        }
 
+prepare_to_open:
        if (dry_run || read_batch) {
                write_int(f_out,i);
                return;
@@ -487,14 +502,9 @@ static void recv_generator(char *fname, struct file_struct *file, int i,
                return;
        }
 
-       if (partial_dir) {
-               STRUCT_STAT st2;
-               char *partialptr = partial_dir_fname(fname);
-               if (partialptr && link_stat(partialptr, &st2, 0) == 0
-                   && S_ISREG(st2.st_mode)) {
-                       st = st2;
-                       fnamecmp = partialptr;
-               }
+       if (partialptr) {
+               st = partial_st;
+               fnamecmp = partialptr;
        }
 
        /* open the file */