The patches for 3.2.0pre1.
[rsync-patches.git] / omit-dir-changes.diff
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.
3
4 To 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
10 based-on: c528f8d5c8aa7b16b20cda72a9f4119699890c28
11 diff --git a/generator.c b/generator.c
12 --- a/generator.c
13 +++ b/generator.c
14 @@ -45,6 +45,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 @@ -494,6 +495,7 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
23              const char *xname)
24  {
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 @@ -523,9 +525,9 @@ 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 && (uid_t)F_OWNER(file) != sxp->st.st_uid)
36                         iflags |= ITEM_REPORT_OWNER;
37 -               if (gid_ndx && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file))
38 +               if (gid_ndx && !omit_changes && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file))
39                         iflags |= ITEM_REPORT_GROUP;
40  #ifdef SUPPORT_ACLS
41                 if (preserve_acls && !S_ISLNK(file->mode)) {
42 @@ -1410,7 +1412,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
43                 real_ret = statret;
44                 if (file->flags & FLAG_DIR_CREATED)
45                         statret = -1;
46 -               if (!preserve_perms) { /* See comment in non-dir code below. */
47 +               if (!preserve_perms || omit_dir_changes) { /* See comment in non-dir code below. */
48                         file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms, statret == 0);
49                 }
50                 if (statret != 0 && basis_dir[0] != NULL) {
51 diff --git a/options.c b/options.c
52 --- a/options.c
53 +++ b/options.c
54 @@ -75,6 +75,7 @@ int delete_before = 0;
55  int delete_after = 0;
56  int delete_excluded = 0;
57  int remove_source_files = 0;
58 +int omit_dir_changes = 0;
59  int one_file_system = 0;
60  int protocol_version = PROTOCOL_VERSION;
61  int sparse_files = 0;
62 @@ -796,6 +797,7 @@ static struct poptOption long_options[] = {
63    {"omit-link-times", 'J', POPT_ARG_VAL,    &omit_link_times, 1, 0, 0 },
64    {"no-omit-link-times",0, POPT_ARG_VAL,    &omit_link_times, 0, 0, 0 },
65    {"no-J",             0,  POPT_ARG_VAL,    &omit_link_times, 0, 0, 0 },
66 +  {"omit-dir-changes", 0,  POPT_ARG_NONE,   &omit_dir_changes, 0, 0, 0 },
67    {"modify-window",   '@', POPT_ARG_INT,    &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
68    {"super",            0,  POPT_ARG_VAL,    &am_root, 2, 0, 0 },
69    {"no-super",         0,  POPT_ARG_VAL,    &am_root, 0, 0, 0 },
70 @@ -2204,6 +2206,9 @@ int parse_arguments(int *argc_p, const char ***argv_p)
71                 parse_filter_str(&filter_list, backup_dir_buf, rule_template(0), 0);
72         }
73  
74 +       if (omit_dir_changes)
75 +               omit_dir_times = 1;
76 +
77         if (preserve_times) {
78                 preserve_times = PRESERVE_FILE_TIMES;
79                 if (!omit_dir_times)
80 @@ -2456,6 +2461,8 @@ void server_options(char **args, int *argc_p)
81                         argstr[x++] = 'O';
82                 if (omit_link_times)
83                         argstr[x++] = 'J';
84 +               if (omit_dir_changes == 1)
85 +                       args[ac++] = "--omit-dir-changes";
86                 if (fuzzy_basis) {
87                         argstr[x++] = 'y';
88                         if (fuzzy_basis > 1)
89 diff --git a/rsync.1.md b/rsync.1.md
90 --- a/rsync.1.md
91 +++ b/rsync.1.md
92 @@ -374,6 +374,7 @@ detailed description below for a complete description.
93  --open-noatime           avoid changing the atime on opened files
94  --omit-dir-times, -O     omit directories from --times
95  --omit-link-times, -J    omit symlinks from --times
96 +--omit-dir-changes       omit directories from any attribute changes
97  --super                  receiver attempts super-user activities
98  --fake-super             store/recover privileged attrs using xattrs
99  --sparse, -S             turn sequences of nulls into sparse blocks
100 @@ -1359,6 +1360,11 @@ your home directory (remove the '=' for that).
101      This tells rsync to omit symlinks when it is preserving modification times
102      (see `--times`).
103  
104 +0.  `--omit-dir-changes`
105 +
106 +    This tells rsync to omit directories when applying any preserved attributes
107 +    (owner, group, times, permissions) to already existing directories.
108 +
109  0.  `--super`
110  
111      This tells the receiving side to attempt super-user activities even if the
112 diff --git a/rsync.c b/rsync.c
113 --- a/rsync.c
114 +++ b/rsync.c
115 @@ -33,6 +33,7 @@ extern int preserve_xattrs;
116  extern int preserve_perms;
117  extern int preserve_executability;
118  extern int preserve_times;
119 +extern int omit_dir_changes;
120  extern int am_root;
121  extern int am_server;
122  extern int am_daemon;
123 @@ -519,9 +520,11 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
124                 get_acl(fname, sxp);
125  #endif
126  
127 -       change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file);
128 +       change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file)
129 +                 && !(omit_dir_changes && S_ISDIR(sxp->st.st_mode));
130         change_gid = gid_ndx && !(file->flags & FLAG_SKIP_GROUP)
131 -                 && sxp->st.st_gid != (gid_t)F_GROUP(file);
132 +                 && sxp->st.st_gid != (gid_t)F_GROUP(file)
133 +                 && !(omit_dir_changes && S_ISDIR(sxp->st.st_mode));
134  #ifndef CAN_CHOWN_SYMLINK
135         if (S_ISLNK(sxp->st.st_mode)) {
136                 ;