Adding the --fake-super option.
[rsync/rsync.git] / rsync.c
diff --git a/rsync.c b/rsync.c
index 676e658..1eda740 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -257,6 +257,8 @@ int set_file_attrs(const char *fname, struct file_struct *file, statx *sxp,
 #ifdef SUPPORT_XATTRS
        if (preserve_xattrs && fnamecmp)
                set_xattr(fname, file, fnamecmp, sxp);
+       if (am_root < 0)
+               set_stat_xattr(fname, file);
 #endif
 
        if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
@@ -296,7 +298,9 @@ int set_file_attrs(const char *fname, struct file_struct *file, statx *sxp,
                                        (long)sxp->st.st_gid, (long)F_GID(file));
                        }
                }
-               if (do_lchown(fname,
+               if (am_root < 0) {
+                       ;
+               } else if (do_lchown(fname,
                    change_uid ? F_UID(file) : sxp->st.st_uid,
                    change_gid ? F_GID(file) : sxp->st.st_gid) != 0) {
                        /* shouldn't have attempted to change uid or gid
@@ -305,7 +309,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, statx *sxp,
                            change_uid ? "chown" : "chgrp",
                            full_fname(fname));
                        goto cleanup;
-               }
+               } else
                /* 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 */
@@ -332,7 +336,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, statx *sxp,
 
 #ifdef HAVE_CHMOD
        if (!BITS_EQUAL(sxp->st.st_mode, new_mode, CHMOD_BITS)) {
-               int 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",