Fix some fuzz in the --help text hunks.
[rsync/rsync-patches.git] / early-chmod.diff
1 --- orig/rsync.c        2004-07-23 17:16:13
2 +++ rsync.c     2004-07-26 06:27:27
3 @@ -246,6 +246,9 @@ void finish_transfer(char *fname, char *
4                 goto do_set_perms;
5         }
6  
7 +       /* Change permissions before putting the file into place. */
8 +       set_perms(fnametmp, file, NULL, ok_to_set_time ? 0 : PERMS_SKIP_MTIME);
9 +
10         /* move tmp file over real file */
11         if (verbose > 2)
12                 rprintf(FINFO, "renaming %s to %s\n", fnametmp, fname);
13 @@ -257,6 +260,10 @@ void finish_transfer(char *fname, char *
14                 do_unlink(fnametmp);
15                 return;
16         }
17 +       if (ret == 0) {
18 +               /* The file was moved into place (not copied), so it's done. */
19 +               return;
20 +       }
21      do_set_perms:
22         set_perms(fname, file, NULL, ok_to_set_time ? 0 : PERMS_SKIP_MTIME);
23  }
24 --- orig/t_stub.c       2004-05-15 20:10:13
25 +++ t_stub.c    2004-07-03 20:17:55
26 @@ -26,6 +26,7 @@
27   * functions, so that module test harnesses can run standalone.
28   **/
29  
30 +int am_root = 0;
31  int modify_window = 0;
32  int module_id = -1;
33  struct exclude_list_struct server_exclude_list;
34 --- orig/util.c 2004-06-09 21:54:47
35 +++ util.c      2004-07-03 20:17:55
36 @@ -29,6 +29,7 @@
37  
38  extern int verbose;
39  extern int dry_run;
40 +extern int am_root;
41  extern int module_id;
42  extern int modify_window;
43  extern struct exclude_list_struct server_exclude_list;
44 @@ -263,6 +264,8 @@ int copy_file(char *source, char *dest, 
45                 return -1;
46         }
47  
48 +       if (!am_root && !(mode & S_IWUSR))
49 +               mode |= S_IWUSR;
50         ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode);
51         if (ofd == -1) {
52                 rsyserr(FERROR, errno, "open %s", full_fname(dest));
53 @@ -361,8 +364,8 @@ int robust_unlink(char *fname)
54  #endif
55  }
56  
57 -/* Returns 0 on success, -1 on most errors, and -2 if we got an error
58 - * trying to copy the file across file systems. */
59 +/* Returns 0 on successful rename, 1 if we successfully copied the file
60 + * across filesystems, -2 if copy_file() failed, and -1 on other errors. */
61  int robust_rename(char *from, char *to, int mode)
62  {
63         int tries = 4;
64 @@ -379,10 +382,12 @@ int robust_rename(char *from, char *to, 
65                         break;
66  #endif
67                 case EXDEV:
68 +                       if (!am_root && !(mode & S_IRUSR))
69 +                               do_chmod(from, (mode & CHMOD_BITS) | S_IRUSR);
70                         if (copy_file(from, to, mode) != 0)
71                                 return -2;
72                         do_unlink(from);
73 -                       return 0;
74 +                       return 1;
75                 default:
76                         return -1;
77                 }