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 diff --git a/generator.c b/generator.c
13 @@ -44,6 +44,7 @@ extern int preserve_hard_links;
14 extern int preserve_executability;
15 extern int preserve_perms;
16 extern int preserve_times;
17 +extern int omit_dir_changes;
20 extern int delete_mode;
21 @@ -627,6 +628,7 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
24 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
25 + int omit_changes = omit_dir_changes && S_ISDIR(sxp->st.st_mode);
26 int keep_time = !preserve_times ? 0
27 : S_ISDIR(file->mode) ? preserve_times > 1 :
28 #if defined HAVE_LUTIMES && defined HAVE_UTIMES
29 @@ -656,10 +658,11 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
30 } else if (preserve_executability
31 && ((sxp->st.st_mode & 0111 ? 1 : 0) ^ (file->mode & 0111 ? 1 : 0)))
32 iflags |= ITEM_REPORT_PERMS;
33 - if (uid_ndx && am_root && (uid_t)F_OWNER(file) != sxp->st.st_uid)
34 + if (uid_ndx && am_root && !omit_changes
35 + && (uid_t)F_OWNER(file) != sxp->st.st_uid)
36 iflags |= ITEM_REPORT_OWNER;
37 - if (gid_ndx && !(file->flags & FLAG_SKIP_GROUP)
38 - && sxp->st.st_gid != (gid_t)F_GROUP(file))
39 + if (gid_ndx && !omit_changes
40 + && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file))
41 iflags |= ITEM_REPORT_GROUP;
43 if (preserve_acls && !S_ISLNK(file->mode)) {
44 @@ -1435,7 +1438,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
46 if (file->flags & FLAG_DIR_CREATED)
48 - if (!preserve_perms) { /* See comment in non-dir code below. */
49 + if (!preserve_perms || omit_dir_changes) { /* See comment in non-dir code below. */
50 file->mode = dest_mode(file->mode, sx.st.st_mode,
51 dflt_perms, statret == 0);
53 diff --git a/options.c b/options.c
56 @@ -59,6 +59,7 @@ int preserve_specials = 0;
59 int preserve_times = 0;
60 +int omit_dir_changes = 0;
64 @@ -353,6 +354,7 @@ void usage(enum logcode F)
65 rprintf(F," -D same as --devices --specials\n");
66 rprintf(F," -t, --times preserve modification times\n");
67 rprintf(F," -O, --omit-dir-times omit directories from --times\n");
68 + rprintf(F," --omit-dir-changes omit directories from any attribute changes\n");
69 rprintf(F," --super receiver attempts super-user activities\n");
71 rprintf(F," --fake-super store/recover privileged attrs using xattrs\n");
72 @@ -493,6 +495,7 @@ static struct poptOption long_options[] = {
73 {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 1, 0, 0 },
74 {"no-omit-dir-times",0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
75 {"no-O", 0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
76 + {"omit-dir-changes", 0, POPT_ARG_NONE, &omit_dir_changes, 0, 0, 0 },
77 {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
78 {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
79 {"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 },
80 @@ -1509,6 +1512,8 @@ int parse_arguments(int *argc_p, const char ***argv_p)
81 parse_rule(&filter_list, backup_dir_buf, 0, 0);
84 + if (omit_dir_changes)
86 if (make_backups && !backup_dir) {
87 omit_dir_times = 0; /* Implied, so avoid -O to sender. */
88 if (preserve_times > 1)
89 @@ -1747,6 +1752,8 @@ void server_options(char **args, int *argc_p)
93 + if (omit_dir_changes == 1)
94 + args[ac++] = "--omit-dir-changes";
98 diff --git a/rsync.c b/rsync.c
101 @@ -34,6 +34,7 @@ extern int preserve_xattrs;
102 extern int preserve_perms;
103 extern int preserve_executability;
104 extern int preserve_times;
105 +extern int omit_dir_changes;
107 extern int am_server;
108 extern int am_sender;
109 @@ -439,9 +440,11 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
110 file->flags |= FLAG_TIME_FAILED;
113 - change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file);
114 + change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file)
115 + && !(omit_dir_changes && S_ISDIR(sxp->st.st_mode));
116 change_gid = gid_ndx && !(file->flags & FLAG_SKIP_GROUP)
117 - && sxp->st.st_gid != (gid_t)F_GROUP(file);
118 + && sxp->st.st_gid != (gid_t)F_GROUP(file)
119 + && !(omit_dir_changes && S_ISDIR(sxp->st.st_mode));
120 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
121 if (S_ISLNK(sxp->st.st_mode)) {
123 diff --git a/rsync.yo b/rsync.yo
126 @@ -349,6 +349,7 @@ to the detailed description below for a complete description. verb(
127 -D same as --devices --specials
128 -t, --times preserve modification times
129 -O, --omit-dir-times omit directories from --times
130 + --omit-dir-changes omit directories from any attribute changes
131 --super receiver attempts super-user activities
132 --fake-super store/recover privileged attrs using xattrs
133 -S, --sparse handle sparse files efficiently
134 @@ -1000,6 +1001,10 @@ it is preserving modification times (see bf(--times)). If NFS is sharing
135 the directories on the receiving side, it is a good idea to use bf(-O).
136 This option is inferred if you use bf(--backup) without bf(--backup-dir).
138 +dit(bf(--omit-dir-changes)) This tells rsync to omit directories when applying
139 +any preserved attributes (owner, group, times, permissions) to already existing
142 dit(bf(--super)) This tells the receiving side to attempt super-user
143 activities even if the receiving rsync wasn't run by the super-user. These
144 activities include: preserving users via the bf(--owner) option, preserving