Updated patches to work with the current trunk.
[rsync/rsync-patches.git] / omit-dir-changes.diff
CommitLineData
59d64e0b
WD
1This patch from Antti Tapaninen added the --omit-dir-changes option, which
2tells rsync to not affect any attributes on the directories in the transfer.
3
03019e41
WD
4To use this patch, run these commands for a successful build:
5
6 patch -p1 <patches/omit-dir-changes.diff
7 ./configure (optional if already run)
8 make
9
cc3e685d 10diff --git a/generator.c b/generator.c
fc557362 11index 12007a1..29c9297 100644
cc3e685d
WD
12--- a/generator.c
13+++ b/generator.c
c0c7984e 14@@ -44,6 +44,7 @@ extern int preserve_hard_links;
85096e5e 15 extern int preserve_executability;
898a2112 16 extern int preserve_perms;
59d64e0b 17 extern int preserve_times;
59d64e0b 18+extern int omit_dir_changes;
898a2112
WD
19 extern int uid_ndx;
20 extern int gid_ndx;
59d64e0b 21 extern int delete_mode;
fc557362 22@@ -437,6 +438,7 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
c0c7984e
WD
23 const char *xname)
24 {
25 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
eab3568b 26+ int omit_changes = omit_dir_changes && S_ISDIR(sxp->st.st_mode);
c0c7984e
WD
27 int keep_time = !preserve_times ? 0
28 : S_ISDIR(file->mode) ? preserve_times > 1 :
29 #if defined HAVE_LUTIMES && defined HAVE_UTIMES
fc557362 30@@ -466,10 +468,11 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
c0c7984e
WD
31 } else if (preserve_executability
32 && ((sxp->st.st_mode & 0111 ? 1 : 0) ^ (file->mode & 0111 ? 1 : 0)))
59d64e0b 33 iflags |= ITEM_REPORT_PERMS;
898a2112
WD
34- if (uid_ndx && am_root && (uid_t)F_OWNER(file) != sxp->st.st_uid)
35+ if (uid_ndx && am_root && !omit_changes
19036ed8 36+ && (uid_t)F_OWNER(file) != sxp->st.st_uid)
59d64e0b 37 iflags |= ITEM_REPORT_OWNER;
898a2112 38- if (gid_ndx && !(file->flags & FLAG_SKIP_GROUP)
19036ed8 39- && sxp->st.st_gid != (gid_t)F_GROUP(file))
898a2112 40+ if (gid_ndx && !omit_changes
30c5d6b4 41+ && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file))
59d64e0b 42 iflags |= ITEM_REPORT_GROUP;
ffc18846
WD
43 #ifdef SUPPORT_ACLS
44 if (preserve_acls && !S_ISLNK(file->mode)) {
fc557362 45@@ -1254,7 +1257,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
f2acdf8c
WD
46 real_sx = sx;
47 if (file->flags & FLAG_DIR_CREATED)
48 statret = -1;
2f999b32
WD
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. */
ffc18846
WD
51 file->mode = dest_mode(file->mode, sx.st.st_mode,
52 dflt_perms, statret == 0);
2f999b32 53 }
cc3e685d 54diff --git a/options.c b/options.c
fc557362 55index e7c6c61..03588fd 100644
cc3e685d
WD
56--- a/options.c
57+++ b/options.c
c0c7984e 58@@ -59,6 +59,7 @@ int preserve_specials = 0;
a54a2c4d 59 int preserve_uid = 0;
59d64e0b
WD
60 int preserve_gid = 0;
61 int preserve_times = 0;
59d64e0b
WD
62+int omit_dir_changes = 0;
63 int update_only = 0;
64 int cvs_exclude = 0;
65 int dry_run = 0;
fc557362 66@@ -698,6 +699,7 @@ void usage(enum logcode F)
59d64e0b 67 rprintf(F," -D same as --devices --specials\n");
671e613f
WD
68 rprintf(F," -t, --times preserve modification times\n");
69 rprintf(F," -O, --omit-dir-times omit directories from --times\n");
6af518aa 70+ rprintf(F," --omit-dir-changes omit directories from any attribute changes\n");
59d64e0b 71 rprintf(F," --super receiver attempts super-user activities\n");
8f0fca7a
WD
72 #ifdef SUPPORT_XATTRS
73 rprintf(F," --fake-super store/recover privileged attrs using xattrs\n");
fc557362 74@@ -848,6 +850,7 @@ static struct poptOption long_options[] = {
a54a2c4d
WD
75 {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 1, 0, 0 },
76 {"no-omit-dir-times",0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
77 {"no-O", 0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
59d64e0b
WD
78+ {"omit-dir-changes", 0, POPT_ARG_NONE, &omit_dir_changes, 0, 0, 0 },
79 {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
80 {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
81 {"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 },
fc557362 82@@ -2020,6 +2023,8 @@ int parse_arguments(int *argc_p, const char ***argv_p)
6af518aa 83 parse_rule(&filter_list, backup_dir_buf, 0, 0);
59d64e0b 84 }
59d64e0b 85
a54a2c4d
WD
86+ if (omit_dir_changes)
87+ omit_dir_times = 1;
88 if (make_backups && !backup_dir) {
89 omit_dir_times = 0; /* Implied, so avoid -O to sender. */
90 if (preserve_times > 1)
fc557362 91@@ -2263,6 +2268,8 @@ void server_options(char **args, int *argc_p)
59d64e0b 92 argstr[x++] = 'm';
a54a2c4d 93 if (omit_dir_times)
59d64e0b
WD
94 argstr[x++] = 'O';
95+ if (omit_dir_changes == 1)
96+ args[ac++] = "--omit-dir-changes";
97 } else {
98 if (copy_links)
99 argstr[x++] = 'L';
cc3e685d 100diff --git a/rsync.c b/rsync.c
fc557362 101index 2c026a2..caf3204 100644
cc3e685d
WD
102--- a/rsync.c
103+++ b/rsync.c
fc557362 104@@ -33,6 +33,7 @@ extern int preserve_xattrs;
a54a2c4d 105 extern int preserve_perms;
59d64e0b
WD
106 extern int preserve_executability;
107 extern int preserve_times;
59d64e0b
WD
108+extern int omit_dir_changes;
109 extern int am_root;
110 extern int am_server;
111 extern int am_sender;
fc557362 112@@ -438,9 +439,11 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
85096e5e 113 file->flags |= FLAG_TIME_FAILED;
59d64e0b
WD
114 }
115
898a2112
WD
116- change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file);
117+ change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file)
8f0fca7a 118+ && !(omit_dir_changes && S_ISDIR(sxp->st.st_mode));
898a2112 119 change_gid = gid_ndx && !(file->flags & FLAG_SKIP_GROUP)
19036ed8
WD
120- && sxp->st.st_gid != (gid_t)F_GROUP(file);
121+ && sxp->st.st_gid != (gid_t)F_GROUP(file)
8f0fca7a 122+ && !(omit_dir_changes && S_ISDIR(sxp->st.st_mode));
59d64e0b 123 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
6af518aa 124 if (S_ISLNK(sxp->st.st_mode)) {
59d64e0b 125 ;
cc3e685d 126diff --git a/rsync.yo b/rsync.yo
fc557362 127index 941f7a5..9aef20a 100644
cc3e685d
WD
128--- a/rsync.yo
129+++ b/rsync.yo
fc557362 130@@ -356,6 +356,7 @@ to the detailed description below for a complete description. verb(
6af518aa
WD
131 -D same as --devices --specials
132 -t, --times preserve modification times
133 -O, --omit-dir-times omit directories from --times
134+ --omit-dir-changes omit directories from any attribute changes
135 --super receiver attempts super-user activities
136 --fake-super store/recover privileged attrs using xattrs
137 -S, --sparse handle sparse files efficiently
fc557362 138@@ -1071,6 +1072,10 @@ it is preserving modification times (see bf(--times)). If NFS is sharing
6af518aa
WD
139 the directories on the receiving side, it is a good idea to use bf(-O).
140 This option is inferred if you use bf(--backup) without bf(--backup-dir).
141
142+dit(bf(--omit-dir-changes)) This tells rsync to omit directories when applying
143+any preserved attributes (owner, group, times, permissions) to already existing
144+directories.
145+
146 dit(bf(--super)) This tells the receiving side to attempt super-user
147 activities even if the receiving rsync wasn't run by the super-user. These
148 activities include: preserving users via the bf(--owner) option, preserving