Commit | Line | Data |
---|---|---|
81486408 WD |
1 | --- backup.c 23 Feb 2004 07:03:03 -0000 1.27 |
2 | +++ backup.c 6 Mar 2004 07:25:05 -0000 | |
3 | @@ -130,8 +130,8 @@ failure: | |
4 | /* robustly move a file, creating new directory structures if necessary */ | |
5 | static int robust_move(char *src, char *dst) | |
6 | { | |
7 | - if (robust_rename(src, dst, 0755) != 0 && (errno != ENOENT | |
8 | - || make_bak_dir(dst) < 0 || robust_rename(src, dst, 0755) != 0)) | |
9 | + if (robust_rename(src, dst, 0755) < 0 && (errno != ENOENT | |
10 | + || make_bak_dir(dst) < 0 || robust_rename(src, dst, 0755) < 0)) | |
11 | return -1; | |
12 | return 0; | |
13 | } | |
14 | --- rsync.c 25 Feb 2004 21:20:59 -0000 1.133 | |
15 | +++ rsync.c 6 Mar 2004 07:25:05 -0000 | |
16 | @@ -235,15 +235,19 @@ void finish_transfer(char *fname, char * | |
17 | if (make_backups && !make_backup(fname)) | |
18 | return; | |
19 | ||
20 | + /* Change permissions before putting the file into place. */ | |
21 | + set_perms(fnametmp, file, NULL, 0); | |
22 | + | |
23 | /* move tmp file over real file */ | |
24 | ret = robust_rename(fnametmp, fname, file->mode & INITACCESSPERMS); | |
25 | - if (ret != 0) { | |
26 | + if (ret < 0) { | |
27 | rprintf(FERROR, "%s %s -> \"%s\": %s\n", | |
28 | ret == -2 ? "copy" : "rename", | |
29 | full_fname(fnametmp), fname, strerror(errno)); | |
30 | do_unlink(fnametmp); | |
31 | - } else { | |
32 | - set_perms(fname,file,NULL,0); | |
33 | + } else if (ret == 1) { | |
34 | + /* The file got copied, so set the permissions again. */ | |
35 | + set_perms(fname, file, NULL, 0); | |
36 | } | |
37 | } | |
38 | ||
39 | --- t_stub.c 11 Sep 2003 04:48:13 -0000 1.4 | |
40 | +++ t_stub.c 6 Mar 2004 07:25:05 -0000 | |
41 | @@ -26,6 +26,7 @@ | |
42 | * functions, so that module test harnesses can run standalone. | |
43 | **/ | |
44 | ||
45 | +int am_root = 0; | |
46 | int modify_window = 0; | |
47 | int module_id = -1; | |
48 | struct exclude_struct **server_exclude_list; | |
49 | --- util.c 17 Feb 2004 23:13:10 -0000 1.132 | |
50 | +++ util.c 6 Mar 2004 07:25:06 -0000 | |
51 | @@ -28,6 +28,7 @@ | |
52 | #include "rsync.h" | |
53 | ||
54 | extern int verbose; | |
55 | +extern int am_root; | |
56 | ||
57 | int sanitize_paths = 0; | |
58 | ||
59 | @@ -262,6 +263,8 @@ int copy_file(char *source, char *dest, | |
60 | return -1; | |
61 | } | |
62 | ||
63 | + if (!am_root && !(mode & S_IWRITE)) | |
64 | + mode |= S_IWRITE; | |
65 | ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode); | |
66 | if (ofd == -1) { | |
67 | rprintf(FERROR,"open %s: %s\n", | |
68 | @@ -353,8 +356,8 @@ int robust_unlink(char *fname) | |
69 | #endif | |
70 | } | |
71 | ||
72 | -/* Returns 0 on success, -1 on most errors, and -2 if we got an error | |
73 | - * trying to copy the file across file systems. */ | |
74 | +/* Returns 0 on successful rename, 1 if we successfully copied the file | |
75 | + * across filesystems, -2 if copy_file() failed, and -1 on other errors. */ | |
76 | int robust_rename(char *from, char *to, int mode) | |
77 | { | |
78 | int tries = 4; | |
79 | @@ -371,10 +374,12 @@ int robust_rename(char *from, char *to, | |
80 | break; | |
81 | #endif | |
82 | case EXDEV: | |
83 | + if (!am_root && !(mode & S_IREAD)) | |
84 | + do_chmod(from, (mode & CHMOD_BITS) | S_IREAD); | |
85 | if (copy_file(from, to, mode) != 0) | |
86 | return -2; | |
87 | do_unlink(from); | |
88 | - return 0; | |
89 | + return 1; | |
90 | default: | |
91 | return -1; | |
92 | } |