Updated rsync.yo hunk.
[rsync/rsync-patches.git] / early-chmod.diff
CommitLineData
1931a970
WD
1--- rsync.c 13 Mar 2004 20:18:03 -0000 1.134
2+++ rsync.c 13 Mar 2004 20:19:40 -0000
3@@ -235,6 +235,9 @@ void finish_transfer(char *fname, char *
81486408
WD
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);
1931a970
WD
12 if (ret < 0) {
13@@ -242,8 +245,9 @@ void finish_transfer(char *fname, char *
81486408
WD
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 11 Sep 2003 04:48:13 -0000 1.4
1931a970 26+++ t_stub.c 13 Mar 2004 20:19:40 -0000
81486408
WD
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_struct **server_exclude_list;
35--- util.c 17 Feb 2004 23:13:10 -0000 1.132
1931a970 36+++ util.c 13 Mar 2004 20:19:40 -0000
81486408
WD
37@@ -28,6 +28,7 @@
38 #include "rsync.h"
39
40 extern int verbose;
41+extern int am_root;
42
43 int sanitize_paths = 0;
44
45@@ -262,6 +263,8 @@ int copy_file(char *source, char *dest,
46 return -1;
47 }
48
fbcc0c79
WD
49+ if (!am_root && !(mode & S_IWUSR))
50+ mode |= S_IWUSR;
81486408
WD
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@@ -353,8 +356,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@@ -371,10 +374,12 @@ int robust_rename(char *from, char *to,
66 break;
67 #endif
68 case EXDEV:
fbcc0c79
WD
69+ if (!am_root && !(mode & S_IRUSR))
70+ do_chmod(from, (mode & CHMOD_BITS) | S_IRUSR);
81486408
WD
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 }