Move var declaration for older C compilers.
[rsync.git] / rsync.c
diff --git a/rsync.c b/rsync.c
index 91fb9e3088e50b4203ee0084a74929233be71d8a..c42d55352e1917ec5052c20418e9eedba8bf8dae 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -41,8 +41,6 @@ extern int am_generator;
 extern int am_starting_up;
 extern int allow_8bit_chars;
 extern int protocol_version;
-extern int uid_ndx;
-extern int gid_ndx;
 extern int inc_recurse;
 extern int inplace;
 extern int flist_eof;
@@ -495,7 +493,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
                flags |= ATTRS_SKIP_MTIME;
        if (!(flags & ATTRS_SKIP_MTIME)
            && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
-               int ret = set_modtime(fname, file->modtime, F_MOD_NSEC(file), file->mode);
+               int ret = set_modtime(fname, file->modtime, F_MOD_NSEC(file), sxp->st.st_mode);
                if (ret < 0) {
                        rsyserr(FERROR_XFER, errno, "failed to set times on %s",
                                full_fname(fname));
@@ -510,7 +508,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
        change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file);
        change_gid = gid_ndx && !(file->flags & FLAG_SKIP_GROUP)
                  && sxp->st.st_gid != (gid_t)F_GROUP(file);
-#if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
+#ifndef CAN_CHOWN_SYMLINK
        if (S_ISLNK(sxp->st.st_mode)) {
                ;
        } else
@@ -529,9 +527,9 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
                        }
                }
                if (am_root >= 0) {
-                       if (do_lchown(fname,
-                           change_uid ? (uid_t)F_OWNER(file) : sxp->st.st_uid,
-                           change_gid ? (gid_t)F_GROUP(file) : sxp->st.st_gid) != 0) {
+                       uid_t uid = change_uid ? (uid_t)F_OWNER(file) : sxp->st.st_uid;
+                       gid_t gid = change_gid ? (gid_t)F_GROUP(file) : sxp->st.st_gid;
+                       if (do_lchown(fname, uid, gid) != 0) {
                                /* We shouldn't have attempted to change uid
                                 * or gid unless have the privilege. */
                                rsyserr(FERROR_XFER, errno, "%s %s failed",
@@ -539,6 +537,10 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
                                    full_fname(fname));
                                goto cleanup;
                        }
+                       if (uid == (uid_t)-1 && sxp->st.st_uid != (uid_t)-1)
+                               rprintf(FERROR_XFER, "uid 4294967295 (-1) is impossible to set on %s\n", full_fname(fname));
+                       if (gid == (gid_t)-1 && sxp->st.st_gid != (gid_t)-1)
+                               rprintf(FERROR_XFER, "gid 4294967295 (-1) is impossible to set on %s\n", full_fname(fname));
                        /* A lchown had been done, so we need to re-stat if
                         * the destination had the setuid or setgid bits set
                         * (due to the side effect of the chown call). */