X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/bd685982389b78a158921b7839bdeca501338d19..HEAD:/generator.c diff --git a/generator.c b/generator.c index 84913007..d5dc85f5 100644 --- a/generator.c +++ b/generator.c @@ -377,13 +377,30 @@ static void do_delete_pass(void) rprintf(FINFO, " \r"); } -static inline int time_differs(struct file_struct *file, stat_x *sxp) +static BOOL preserve_time_of(struct file_struct *file) { - return cmp_time(sxp->st.st_mtime, file->modtime); + if (S_ISDIR(file->mode)) + return preserve_times & PRESERVE_DIR_TIMES; + else if (S_ISLNK(file->mode)) + /* PRESERVE_LINK_TIMES will only be set if CAN_SET_SYMLINK_TIMES. */ + return preserve_times & PRESERVE_LINK_TIMES; + else + return preserve_times; +} + +static BOOL report_time(struct file_struct *file, stat_x *sxp) +{ + return preserve_time_of(file) && + cmp_time(sxp->st.st_mtime, file->modtime); } -static inline int perms_differ(struct file_struct *file, stat_x *sxp) +static BOOL report_perms(struct file_struct *file, stat_x *sxp) { +#ifndef CAN_CHMOD_SYMLINK + if (S_ISLNK(file->mode)) + return 0; +#endif + if (preserve_perms) return !BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS); @@ -393,20 +410,34 @@ static inline int perms_differ(struct file_struct *file, stat_x *sxp) return 0; } -static inline int ownership_differs(struct file_struct *file, stat_x *sxp) +static BOOL report_owner(struct file_struct *file, stat_x *sxp) { - if (am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file)) - return 1; +#ifndef CAN_CHOWN_SYMLINK + if (S_ISLNK(file->mode)) + return 0; +#endif - if (gid_ndx && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file)) - return 1; + return uid_ndx && am_root && sxp->st.st_uid != (uid_t)F_OWNER(file); +} - return 0; +static BOOL report_group(struct file_struct *file, stat_x *sxp) +{ +#ifndef CAN_CHOWN_SYMLINK + if (S_ISLNK(file->mode)) + return 0; +#endif + + return gid_ndx && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file); } #ifdef SUPPORT_ACLS -static inline int acls_differ(const char *fname, struct file_struct *file, stat_x *sxp) +static BOOL report_acls(const char *fname, struct file_struct *file, stat_x *sxp) { +#ifndef CAN_SET_SYMLINK_ACLS /* not currently */ + if (S_ISLNK(file->mode)) + return 0; +#endif + if (preserve_acls) { if (!ACL_READY(*sxp)) get_acl(fname, sxp); @@ -419,12 +450,18 @@ static inline int acls_differ(const char *fname, struct file_struct *file, stat_ #endif #ifdef SUPPORT_XATTRS -static inline int xattrs_differ(const char *fname, struct file_struct *file, stat_x *sxp) +static BOOL report_xattrs(const char *fname, struct file_struct *file, stat_x *sxp, + BOOL mark_needed) { +#ifdef NO_SYMLINK_XATTRS + if (S_ISLNK(file->mode)) + return 0; +#endif + if (preserve_xattrs) { if (!XATTR_READY(*sxp)) get_xattr(fname, sxp); - if (xattr_diff(file, sxp, 0)) + if (xattr_diff(file, sxp, mark_needed)) return 1; } @@ -434,45 +471,17 @@ static inline int xattrs_differ(const char *fname, struct file_struct *file, sta int unchanged_attrs(const char *fname, struct file_struct *file, stat_x *sxp) { - if (S_ISLNK(file->mode)) { -#ifdef CAN_SET_SYMLINK_TIMES - if (preserve_times & PRESERVE_LINK_TIMES && time_differs(file, sxp)) - return 0; -#endif -#ifdef CAN_CHMOD_SYMLINK - if (perms_differ(file, sxp)) - return 0; -#endif -#ifndef CAN_CHOWN_SYMLINK - if (ownership_differs(file, sxp)) - return 0; -#endif -#if defined SUPPORT_ACLS && 0 /* no current symlink-ACL support */ - if (acls_differ(fname, file, sxp)) - return 0; -#endif -#if defined SUPPORT_XATTRS && !defined NO_SYMLINK_XATTRS - if (xattrs_differ(fname, file, sxp)) - return 0; -#endif - } else { - if (preserve_times && time_differs(file, sxp)) - return 0; - if (perms_differ(file, sxp)) - return 0; - if (ownership_differs(file, sxp)) - return 0; + return !(report_time(file, sxp) + || report_perms(file, sxp) + || report_owner(file, sxp) + || report_group(file, sxp) #ifdef SUPPORT_ACLS - if (acls_differ(fname, file, sxp)) - return 0; + || report_acls(fname, file, sxp) #endif #ifdef SUPPORT_XATTRS - if (xattrs_differ(fname, file, sxp)) - return 0; + || report_xattrs(fname, file, sxp, False) #endif - } - - return 1; + ); } void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statret, @@ -480,56 +489,33 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre const char *xname) { if (statret >= 0) { /* A from-dest-dir statret can == 1! */ - int keep_time = !preserve_times ? 0 - : S_ISDIR(file->mode) ? preserve_times & PRESERVE_DIR_TIMES - : S_ISLNK(file->mode) ? preserve_times & PRESERVE_LINK_TIMES - : 1; - if (S_ISREG(file->mode) && F_LENGTH(file) != sxp->st.st_size) iflags |= ITEM_REPORT_SIZE; if (file->flags & FLAG_TIME_FAILED) { /* symlinks only */ if (iflags & ITEM_LOCAL_CHANGE) iflags |= symlink_timeset_failed_flags; - } else if (keep_time + } else if (preserve_time_of(file) ? cmp_time(file->modtime, sxp->st.st_mtime) != 0 : iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !(iflags & ITEM_MATCHED) && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname)) iflags |= ITEM_REPORT_TIME; -#if !defined HAVE_LCHMOD && !defined HAVE_SETATTRLIST - if (S_ISLNK(file->mode)) { - ; - } else -#endif - if (preserve_perms) { - if (!BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS)) - iflags |= ITEM_REPORT_PERMS; - } else if (preserve_executability - && ((sxp->st.st_mode & 0111 ? 1 : 0) ^ (file->mode & 0111 ? 1 : 0))) + if (report_perms(file, sxp)) iflags |= ITEM_REPORT_PERMS; - if (uid_ndx && am_root && (uid_t)F_OWNER(file) != sxp->st.st_uid) + if (report_owner(file, sxp)) iflags |= ITEM_REPORT_OWNER; - if (gid_ndx && !(file->flags & FLAG_SKIP_GROUP) - && sxp->st.st_gid != (gid_t)F_GROUP(file)) + if (report_group(file, sxp)) iflags |= ITEM_REPORT_GROUP; #ifdef SUPPORT_ACLS - if (preserve_acls && !S_ISLNK(file->mode)) { - if (!ACL_READY(*sxp)) - get_acl(fnamecmp, sxp); - if (set_acl(NULL, file, sxp, file->mode)) - iflags |= ITEM_REPORT_ACL; - } + if (report_acls(fnamecmp, file, sxp)) + iflags |= ITEM_REPORT_ACL; #endif #ifdef SUPPORT_XATTRS - if (preserve_xattrs) { - if (!XATTR_READY(*sxp)) - get_xattr(fnamecmp, sxp); - if (xattr_diff(file, sxp, 1)) - iflags |= ITEM_REPORT_XATTR; - } + if (report_xattrs(fnamecmp, file, sxp, True)) + iflags |= ITEM_REPORT_XATTR; #endif } else { #ifdef SUPPORT_XATTRS - if (preserve_xattrs && xattr_diff(file, NULL, 1)) + if (preserve_xattrs && xattr_diff(file, NULL, True)) iflags |= ITEM_REPORT_XATTR; #endif iflags |= ITEM_IS_NEW;