1 This patch from Antti Tapaninen added the --omit-dir-changes option, which
2 tells rsync to not affect any attributes on the directories in the transfer.
4 To use this patch, run these commands for a successful build:
6 patch -p1 <patches/omit-dir-changes.diff
7 ./configure (optional if already run)
10 based-on: 63f91976112b8b2118cc17eb5fc8142175566f4f
11 diff --git a/generator.c b/generator.c
14 @@ -44,6 +44,7 @@ extern int preserve_hard_links;
15 extern int preserve_executability;
16 extern int preserve_perms;
17 extern int preserve_times;
18 +extern int omit_dir_changes;
19 extern int delete_mode;
20 extern int delete_before;
21 extern int delete_during;
22 @@ -481,6 +482,7 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
25 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
26 + int omit_changes = omit_dir_changes && S_ISDIR(sxp->st.st_mode);
27 int keep_time = !preserve_times ? 0
28 : S_ISDIR(file->mode) ? preserve_times & PRESERVE_DIR_TIMES
29 : S_ISLNK(file->mode) ? preserve_times & PRESERVE_LINK_TIMES
30 @@ -507,10 +509,11 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
31 } else if (preserve_executability
32 && ((sxp->st.st_mode & 0111 ? 1 : 0) ^ (file->mode & 0111 ? 1 : 0)))
33 iflags |= ITEM_REPORT_PERMS;
34 - if (uid_ndx && am_root && (uid_t)F_OWNER(file) != sxp->st.st_uid)
35 + if (uid_ndx && am_root && !omit_changes
36 + && (uid_t)F_OWNER(file) != sxp->st.st_uid)
37 iflags |= ITEM_REPORT_OWNER;
38 - if (gid_ndx && !(file->flags & FLAG_SKIP_GROUP)
39 - && sxp->st.st_gid != (gid_t)F_GROUP(file))
40 + if (gid_ndx && !omit_changes
41 + && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file))
42 iflags |= ITEM_REPORT_GROUP;
44 if (preserve_acls && !S_ISLNK(file->mode)) {
45 @@ -1379,7 +1382,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
47 if (file->flags & FLAG_DIR_CREATED)
49 - if (!preserve_perms) { /* See comment in non-dir code below. */
50 + if (!preserve_perms || omit_dir_changes) { /* See comment in non-dir code below. */
51 file->mode = dest_mode(file->mode, sx.st.st_mode,
52 dflt_perms, statret == 0);
54 diff --git a/options.c b/options.c
57 @@ -59,6 +59,7 @@ int preserve_specials = 0;
60 int preserve_times = 0;
61 +int omit_dir_changes = 0;
65 @@ -709,6 +710,7 @@ void usage(enum logcode F)
66 rprintf(F," -t, --times preserve modification times\n");
67 rprintf(F," -O, --omit-dir-times omit directories from --times\n");
68 rprintf(F," -J, --omit-link-times omit symlinks from --times\n");
69 + rprintf(F," --omit-dir-changes omit directories from any attribute changes\n");
70 rprintf(F," --super receiver attempts super-user activities\n");
72 rprintf(F," --fake-super store/recover privileged attrs using xattrs\n");
73 @@ -871,6 +873,7 @@ static struct poptOption long_options[] = {
74 {"omit-link-times", 'J', POPT_ARG_VAL, &omit_link_times, 1, 0, 0 },
75 {"no-omit-link-times",0, POPT_ARG_VAL, &omit_link_times, 0, 0, 0 },
76 {"no-J", 0, POPT_ARG_VAL, &omit_link_times, 0, 0, 0 },
77 + {"omit-dir-changes", 0, POPT_ARG_NONE, &omit_dir_changes, 0, 0, 0 },
78 {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
79 {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
80 {"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 },
81 @@ -2137,6 +2140,9 @@ int parse_arguments(int *argc_p, const char ***argv_p)
82 parse_filter_str(&filter_list, backup_dir_buf, rule_template(0), 0);
85 + if (omit_dir_changes)
89 preserve_times = PRESERVE_FILE_TIMES;
91 @@ -2388,6 +2394,8 @@ void server_options(char **args, int *argc_p)
95 + if (omit_dir_changes == 1)
96 + args[ac++] = "--omit-dir-changes";
100 diff --git a/rsync.c b/rsync.c
103 @@ -33,6 +33,7 @@ extern int preserve_xattrs;
104 extern int preserve_perms;
105 extern int preserve_executability;
106 extern int preserve_times;
107 +extern int omit_dir_changes;
109 extern int am_server;
110 extern int am_daemon;
111 @@ -514,9 +515,11 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
112 file->flags |= FLAG_TIME_FAILED;
115 - change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file);
116 + change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file)
117 + && !(omit_dir_changes && S_ISDIR(sxp->st.st_mode));
118 change_gid = gid_ndx && !(file->flags & FLAG_SKIP_GROUP)
119 - && sxp->st.st_gid != (gid_t)F_GROUP(file);
120 + && sxp->st.st_gid != (gid_t)F_GROUP(file)
121 + && !(omit_dir_changes && S_ISDIR(sxp->st.st_mode));
122 #ifndef CAN_CHOWN_SYMLINK
123 if (S_ISLNK(sxp->st.st_mode)) {
125 diff --git a/rsync.yo b/rsync.yo
128 @@ -371,6 +371,7 @@ to the detailed description below for a complete description. verb(
129 -t, --times preserve modification times
130 -O, --omit-dir-times omit directories from --times
131 -J, --omit-link-times omit symlinks from --times
132 + --omit-dir-changes omit directories from any attribute changes
133 --super receiver attempts super-user activities
134 --fake-super store/recover privileged attrs using xattrs
135 -S, --sparse handle sparse files efficiently
136 @@ -1170,6 +1171,10 @@ This option is inferred if you use bf(--backup) without bf(--backup-dir).
137 dit(bf(-J, --omit-link-times)) This tells rsync to omit symlinks when
138 it is preserving modification times (see bf(--times)).
140 +dit(bf(--omit-dir-changes)) This tells rsync to omit directories when applying
141 +any preserved attributes (owner, group, times, permissions) to already existing
144 dit(bf(--super)) This tells the receiving side to attempt super-user
145 activities even if the receiving rsync wasn't run by the super-user. These
146 activities include: preserving users via the bf(--owner) option, preserving