-@@ -203,6 +205,13 @@ int set_file_attrs(char *fname, struct f
- updated = 1;
+@@ -205,7 +207,19 @@ int set_file_attrs(char *fname, struct f
+
+ #ifdef HAVE_CHMOD
+ if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
+- int ret = do_chmod(fname, file->mode);
++ mode_t mode = file->mode;
++ int ret;
++#ifdef SUPPORT_ACLS
++ /* If we're preserving ACLs, we only want to turn off any
++ * newly-disabled bits here and make sure that the special
++ * permissions are set correctly. We'll let set_acl() turn
++ * on any new access bits as it installs the full ACL. */
++ if (preserve_acls) {
++ mode &= ((S_ISUID | S_ISGID | S_ISVTX)
++ | (st->st_mode & CHMOD_BITS));
++ }
++#endif
++ ret = do_chmod(fname, mode);
+ if (ret < 0) {
+ rsyserr(FERROR, errno,
+ "failed to set permissions on %s",
+@@ -217,6 +231,13 @@ int set_file_attrs(char *fname, struct f