This patch from Antti Tapaninen added the --omit-dir-changes option, which tells rsync to not affect any attributes on the directories in the transfer. To use this patch, run these commands for a successful build: patch -p1 = 0) { /* A from-dest-dir statret can == 1! */ + int omit_changes = omit_dir_changes && S_ISDIR(sxp->st.st_mode); int keep_time = !preserve_times ? 0 : S_ISDIR(file->mode) ? preserve_times & PRESERVE_DIR_TIMES : S_ISLNK(file->mode) ? preserve_times & PRESERVE_LINK_TIMES @@ -544,9 +546,9 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre } else if (preserve_executability && ((sxp->st.st_mode & 0111 ? 1 : 0) ^ (file->mode & 0111 ? 1 : 0))) iflags |= ITEM_REPORT_PERMS; - if (uid_ndx && am_root && (uid_t)F_OWNER(file) != sxp->st.st_uid) + if (uid_ndx && am_root && !omit_changes && (uid_t)F_OWNER(file) != sxp->st.st_uid) iflags |= ITEM_REPORT_OWNER; - if (gid_ndx && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file)) + if (gid_ndx && !omit_changes && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file)) iflags |= ITEM_REPORT_GROUP; #ifdef SUPPORT_ACLS if (preserve_acls && !S_ISLNK(file->mode)) { @@ -1439,7 +1441,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, real_ret = statret; if (file->flags & FLAG_DIR_CREATED) statret = -1; - if (!preserve_perms) { /* See comment in non-dir code below. */ + if (!preserve_perms || omit_dir_changes) { /* See comment in non-dir code below. */ file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms, statret == 0); } if (statret != 0 && basis_dir[0] != NULL) { diff --git a/options.c b/options.c --- a/options.c +++ b/options.c @@ -73,6 +73,7 @@ int delete_before = 0; int delete_after = 0; int delete_excluded = 0; int remove_source_files = 0; +int omit_dir_changes = 0; int one_file_system = 0; int protocol_version = PROTOCOL_VERSION; int sparse_files = 0; @@ -638,6 +639,7 @@ static struct poptOption long_options[] = { {"omit-link-times", 'J', POPT_ARG_VAL, &omit_link_times, 1, 0, 0 }, {"no-omit-link-times",0, POPT_ARG_VAL, &omit_link_times, 0, 0, 0 }, {"no-J", 0, POPT_ARG_VAL, &omit_link_times, 0, 0, 0 }, + {"omit-dir-changes", 0, POPT_ARG_NONE, &omit_dir_changes, 0, 0, 0 }, {"modify-window", '@', POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 }, {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 }, {"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 }, @@ -2255,6 +2257,9 @@ int parse_arguments(int *argc_p, const char ***argv_p) parse_filter_str(&filter_list, backup_dir_buf, rule_template(0), 0); } + if (omit_dir_changes) + omit_dir_times = 1; + if (preserve_times) { preserve_times = PRESERVE_FILE_TIMES; if (!omit_dir_times) @@ -2500,6 +2505,8 @@ void server_options(char **args, int *argc_p) argstr[x++] = 'O'; if (omit_link_times) argstr[x++] = 'J'; + if (omit_dir_changes == 1) + args[ac++] = "--omit-dir-changes"; if (fuzzy_basis) { argstr[x++] = 'y'; if (fuzzy_basis > 1) diff --git a/rsync.1.md b/rsync.1.md --- a/rsync.1.md +++ b/rsync.1.md @@ -376,6 +376,7 @@ detailed description below for a complete description. --crtimes, -N preserve create times (newness) --omit-dir-times, -O omit directories from --times --omit-link-times, -J omit symlinks from --times +--omit-dir-changes omit directories from any attribute changes --super receiver attempts super-user activities --fake-super store/recover privileged attrs using xattrs --sparse, -S turn sequences of nulls into sparse blocks @@ -1405,6 +1406,11 @@ your home directory (remove the '=' for that). This tells rsync to omit symlinks when it is preserving modification times (see `--times`). +0. `--omit-dir-changes` + + This tells rsync to omit directories when applying any preserved attributes + (owner, group, times, permissions) to already existing directories. + 0. `--super` This tells the receiving side to attempt super-user activities even if the diff --git a/rsync.c b/rsync.c --- a/rsync.c +++ b/rsync.c @@ -33,6 +33,7 @@ extern int preserve_xattrs; extern int preserve_perms; extern int preserve_executability; extern int preserve_times; +extern int omit_dir_changes; extern int am_root; extern int am_server; extern int am_daemon; @@ -519,9 +520,11 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp, get_acl(fname, sxp); #endif - change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file); + change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file) + && !(omit_dir_changes && S_ISDIR(sxp->st.st_mode)); change_gid = gid_ndx && !(file->flags & FLAG_SKIP_GROUP) - && sxp->st.st_gid != (gid_t)F_GROUP(file); + && sxp->st.st_gid != (gid_t)F_GROUP(file) + && !(omit_dir_changes && S_ISDIR(sxp->st.st_mode)); #ifndef CAN_CHOWN_SYMLINK if (S_ISLNK(sxp->st.st_mode)) { ; diff -Nurp a/rsync.1 b/rsync.1 --- a/rsync.1 +++ b/rsync.1 @@ -452,6 +452,7 @@ detailed description below for a complet --crtimes, -N preserve create times (newness) --omit-dir-times, -O omit directories from --times --omit-link-times, -J omit symlinks from --times +--omit-dir-changes omit directories from any attribute changes --super receiver attempts super-user activities --fake-super store/recover privileged attrs using xattrs --sparse, -S turn sequences of nulls into sparse blocks @@ -1473,6 +1474,9 @@ these partially-finished directories. .IP "\fB\-\-omit-link-times\fP, \fB\-J\fP" This tells rsync to omit symlinks when it is preserving modification times (see \fB\-\-times\fP). +.IP "\fB\-\-omit-dir-changes\fP" +This tells rsync to omit directories when applying any preserved attributes +(owner, group, times, permissions) to already existing directories. .IP "\fB\-\-super\fP" This tells the receiving side to attempt super-user activities even if the receiving rsync wasn't run by the super-user. These activities include: diff -Nurp a/rsync.1.html b/rsync.1.html --- a/rsync.1.html +++ b/rsync.1.html @@ -367,6 +367,7 @@ detailed description below for a complet --crtimes, -N preserve create times (newness) --omit-dir-times, -O omit directories from --times --omit-link-times, -J omit symlinks from --times +--omit-dir-changes omit directories from any attribute changes --super receiver attempts super-user activities --fake-super store/recover privileged attrs using xattrs --sparse, -S turn sequences of nulls into sparse blocks @@ -1354,6 +1355,11 @@ these partially-finished directories.

--times).

+
--omit-dir-changes
+

This tells rsync to omit directories when applying any preserved attributes +(owner, group, times, permissions) to already existing directories.

+
+
--super

This tells the receiving side to attempt super-user activities even if the receiving rsync wasn't run by the super-user. These activities include: