discard_receive_data(f_in, file->length);
--- old/rsync.c
+++ new/rsync.c
-@@ -197,7 +197,9 @@ int set_file_attrs(char *fname, struct f
+@@ -49,7 +49,6 @@ extern int preserve_gid;
+ extern int inplace;
+ extern int keep_dirlinks;
+ extern int make_backups;
+-extern mode_t orig_umask;
+ extern struct stats stats;
+ extern struct chmod_mode_struct *daemon_chmod_modes;
+
+@@ -197,7 +196,9 @@ int set_file_attrs(char *fname, struct f
(long)sxp->st.st_gid, (long)file->gid);
}
}
change_uid ? file->uid : sxp->st.st_uid,
change_gid ? file->gid : sxp->st.st_gid) != 0) {
/* shouldn't have attempted to change uid or gid
-@@ -206,7 +208,7 @@ int set_file_attrs(char *fname, struct f
+@@ -206,7 +207,7 @@ int set_file_attrs(char *fname, struct f
change_uid ? "chown" : "chgrp",
full_fname(fname));
goto cleanup;
/* a lchown had been done - we have to re-stat if the
* destination had the setuid or setgid bits set due
* to the side effect of the chown call */
-@@ -224,6 +226,24 @@ int set_file_attrs(char *fname, struct f
+@@ -224,6 +225,24 @@ int set_file_attrs(char *fname, struct f
if (preserve_xattrs && set_xattr(fname, file, sxp) == 0)
updated = 1;
#endif
#ifdef SUPPORT_ACLS
/* It's OK to call set_acl() now, even for a dir, as the generator
* will enable owner-writability using chmod, if necessary.
-@@ -237,7 +257,15 @@ int set_file_attrs(char *fname, struct f
+@@ -237,7 +256,7 @@ int set_file_attrs(char *fname, struct f
#ifdef HAVE_CHMOD
if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
- int ret = do_chmod(fname, new_mode);
-+ int ret;
-+ if (am_root < 0) {
-+ mode_t mode = (S_ISDIR(file->mode) ? 0777 : 0666) & ~orig_umask;
-+ if ((sxp->st.st_mode & CHMOD_BITS) != mode)
-+ ret = do_chmod(fname, mode);
-+ else
-+ ret = 0;
-+ } else
-+ ret = do_chmod(fname, new_mode);
++ int ret = am_root < 0 ? 0 : do_chmod(fname, new_mode);
if (ret < 0) {
rsyserr(FERROR, errno,
"failed to set permissions on %s",
#ifdef HAVE_OSX_XATTRS
if (strncmp(rxa->name, unique_prefix, upre_len) == 0) {
rxa->name_len -= upre_len;
-@@ -365,4 +384,100 @@ int set_xattr(const char *fname, const s
+@@ -365,4 +384,103 @@ int set_xattr(const char *fname, const s
return rsync_xal_set(fname, lst + ndx); /* TODO: This needs to return 1 if no xattrs changed! */
}
+{
+ STRUCT_STAT fst, xst;
+ dev_t rdev;
++ mode_t mode;
+
+ if (dry_run)
+ return 0;
+ else
+ rdev = 0;
+
-+ /* This is the mode that the file will be. */
-+ fst.st_mode &= ~CHMOD_BITS;
-+ fst.st_mode |= (S_ISDIR(file->mode) ? 0777 : 0666) & ~orig_umask;
++ /* Force the real file's mode to our liking. */
++ mode = (fst.st_mode & ~CHMOD_BITS)
++ | ((S_ISDIR(fst.st_mode) ? 0777 : 0666) & (~orig_umask | S_IRWXU));
++ if (fst.st_mode != mode)
++ do_chmod(fname, mode);
+ if (!IS_DEVICE(fst.st_mode) && !IS_SPECIAL(fst.st_mode))
+ fst.st_rdev = 0; /* just in case */
+
-+ if (fst.st_mode == file->mode && fst.st_rdev == rdev
++ if (mode == file->mode && fst.st_rdev == rdev
+ && fst.st_uid == file->uid && fst.st_gid == file->gid) {
+ /* xst.st_mode will be 0 if there's no current stat xattr */
+ if (xst.st_mode && sys_lremovexattr(fname, FAKE_XATTR) < 0)