My version of the --copy-atimes patch contributed by Assar.
[rsync-patches.git] / early-chmod.diff
1 --- rsync.c     23 Mar 2004 16:16:15 -0000      1.135
2 +++ rsync.c     15 Apr 2004 19:14:12 -0000
3 @@ -235,6 +235,9 @@ void finish_transfer(char *fname, char *
4         if (make_backups && !make_backup(fname))
5                 return;
6  
7 +       /* Change permissions before putting the file into place. */
8 +       set_perms(fnametmp, file, NULL, 0);
9 +
10         /* move tmp file over real file */
11         ret = robust_rename(fnametmp, fname, file->mode & INITACCESSPERMS);
12         if (ret < 0) {
13 @@ -242,8 +245,9 @@ void finish_transfer(char *fname, char *
14                     ret == -2 ? "copy" : "rename",
15                     full_fname(fnametmp), fname, strerror(errno));
16                 do_unlink(fnametmp);
17 -       } else {
18 -               set_perms(fname,file,NULL,0);
19 +       } else if (ret == 1) {
20 +               /* The file got copied, so set the permissions again. */
21 +               set_perms(fname, file, NULL, 0);
22         }
23  }
24  
25 --- t_stub.c    14 Apr 2004 23:33:34 -0000      1.6
26 +++ t_stub.c    15 Apr 2004 19:14:12 -0000
27 @@ -26,6 +26,7 @@
28   * functions, so that module test harnesses can run standalone.
29   **/
30  
31 +int am_root = 0;
32  int modify_window = 0;
33  int module_id = -1;
34  struct exclude_list_struct server_exclude_list;
35 --- util.c      14 Apr 2004 23:33:34 -0000      1.135
36 +++ util.c      15 Apr 2004 19:14:13 -0000
37 @@ -28,6 +28,7 @@
38  #include "rsync.h"
39  
40  extern int verbose;
41 +extern int am_root;
42  extern struct exclude_list_struct server_exclude_list;
43  
44  int sanitize_paths = 0;
45 @@ -263,6 +264,8 @@ int copy_file(char *source, char *dest, 
46                 return -1;
47         }
48  
49 +       if (!am_root && !(mode & S_IWUSR))
50 +               mode |= S_IWUSR;
51         ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode);
52         if (ofd == -1) {
53                 rprintf(FERROR,"open %s: %s\n",
54 @@ -354,8 +357,8 @@ int robust_unlink(char *fname)
55  #endif
56  }
57  
58 -/* Returns 0 on success, -1 on most errors, and -2 if we got an error
59 - * trying to copy the file across file systems. */
60 +/* Returns 0 on successful rename, 1 if we successfully copied the file
61 + * across filesystems, -2 if copy_file() failed, and -1 on other errors. */
62  int robust_rename(char *from, char *to, int mode)
63  {
64         int tries = 4;
65 @@ -372,10 +375,12 @@ int robust_rename(char *from, char *to, 
66                         break;
67  #endif
68                 case EXDEV:
69 +                       if (!am_root && !(mode & S_IRUSR))
70 +                               do_chmod(from, (mode & CHMOD_BITS) | S_IRUSR);
71                         if (copy_file(from, to, mode) != 0)
72                                 return -2;
73                         do_unlink(from);
74 -                       return 0;
75 +                       return 1;
76                 default:
77                         return -1;
78                 }