| 1 | --- rsync.c 13 May 2004 18:51:22 -0000 1.138 |
| 2 | +++ rsync.c 13 May 2004 19:01:10 -0000 |
| 3 | @@ -236,6 +236,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 | @@ -243,7 +246,8 @@ 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 | + } else if (ret == 1) { |
| 19 | + /* The file got copied, so set the permissions again. */ |
| 20 | set_perms(fname, file, NULL, |
| 21 | ok_to_set_time ? 0 : PERMS_SKIP_MTIME); |
| 22 | } |
| 23 | --- t_stub.c 22 Apr 2004 09:58:11 -0000 1.7 |
| 24 | +++ t_stub.c 13 May 2004 19:01:10 -0000 |
| 25 | @@ -26,6 +26,7 @@ |
| 26 | * functions, so that module test harnesses can run standalone. |
| 27 | **/ |
| 28 | |
| 29 | +int am_root = 0; |
| 30 | int modify_window = 0; |
| 31 | int module_id = -1; |
| 32 | struct exclude_list_struct server_exclude_list; |
| 33 | --- util.c 8 May 2004 20:03:39 -0000 1.142 |
| 34 | +++ util.c 13 May 2004 19:01:10 -0000 |
| 35 | @@ -28,6 +28,7 @@ |
| 36 | #include "rsync.h" |
| 37 | |
| 38 | extern int verbose; |
| 39 | +extern int am_root; |
| 40 | extern struct exclude_list_struct server_exclude_list; |
| 41 | |
| 42 | int sanitize_paths = 0; |
| 43 | @@ -263,6 +264,8 @@ int copy_file(char *source, char *dest, |
| 44 | return -1; |
| 45 | } |
| 46 | |
| 47 | + if (!am_root && !(mode & S_IWUSR)) |
| 48 | + mode |= S_IWUSR; |
| 49 | ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode); |
| 50 | if (ofd == -1) { |
| 51 | rprintf(FERROR,"open %s: %s\n", |
| 52 | @@ -364,8 +367,8 @@ int robust_unlink(char *fname) |
| 53 | #endif |
| 54 | } |
| 55 | |
| 56 | -/* Returns 0 on success, -1 on most errors, and -2 if we got an error |
| 57 | - * trying to copy the file across file systems. */ |
| 58 | +/* Returns 0 on successful rename, 1 if we successfully copied the file |
| 59 | + * across filesystems, -2 if copy_file() failed, and -1 on other errors. */ |
| 60 | int robust_rename(char *from, char *to, int mode) |
| 61 | { |
| 62 | int tries = 4; |
| 63 | @@ -382,10 +385,12 @@ int robust_rename(char *from, char *to, |
| 64 | break; |
| 65 | #endif |
| 66 | case EXDEV: |
| 67 | + if (!am_root && !(mode & S_IRUSR)) |
| 68 | + do_chmod(from, (mode & CHMOD_BITS) | S_IRUSR); |
| 69 | if (copy_file(from, to, mode) != 0) |
| 70 | return -2; |
| 71 | do_unlink(from); |
| 72 | - return 0; |
| 73 | + return 1; |
| 74 | default: |
| 75 | return -1; |
| 76 | } |