Commit | Line | Data |
---|---|---|
a5e6228a | 1 | This patch provides --fileflags, which preserves the st_flags stat() field. |
9f62ddf8 | 2 | Modified from a patch that was written by Rolf Grossmann. |
31611b92 | 3 | |
03019e41 | 4 | To use this patch, run these commands for a successful build: |
9f62ddf8 | 5 | |
03019e41 | 6 | patch -p1 <patches/flags.diff |
9f62ddf8 WD |
7 | ./prepare-source |
8 | ./configure | |
9 | make | |
31611b92 | 10 | |
cc3e685d WD |
11 | diff --git a/compat.c b/compat.c |
12 | --- a/compat.c | |
13 | +++ b/compat.c | |
ccdb48f6 WD |
14 | @@ -44,6 +44,7 @@ extern int protocol_version; |
15 | extern int protect_args; | |
898a2112 WD |
16 | extern int preserve_uid; |
17 | extern int preserve_gid; | |
18 | +extern int preserve_fileflags; | |
19 | extern int preserve_acls; | |
20 | extern int preserve_xattrs; | |
9c25eef5 | 21 | extern int need_messages_from_generator; |
52e09c4e | 22 | @@ -60,7 +61,7 @@ extern iconv_t ic_send, ic_recv; |
ccdb48f6 | 23 | #endif |
898a2112 WD |
24 | |
25 | /* These index values are for the file-list's extra-attribute array. */ | |
d4dd2dd5 WD |
26 | -int uid_ndx, gid_ndx, acls_ndx, xattrs_ndx, unsort_ndx; |
27 | +int uid_ndx, gid_ndx, fileflags_ndx, acls_ndx, xattrs_ndx, unsort_ndx; | |
898a2112 | 28 | |
d4dd2dd5 WD |
29 | #ifdef ICONV_OPTION |
30 | int filesfrom_convert = 0; | |
31 | @@ -124,6 +125,8 @@ void setup_protocol(int f_out,int f_in) | |
898a2112 | 32 | uid_ndx = ++file_extra_cnt; |
fdf967c7 | 33 | if (preserve_gid) |
898a2112 | 34 | gid_ndx = ++file_extra_cnt; |
fdf967c7 | 35 | + if (preserve_fileflags) |
898a2112 | 36 | + fileflags_ndx = ++file_extra_cnt; |
ffc18846 | 37 | if (preserve_acls && !am_sender) |
898a2112 | 38 | acls_ndx = ++file_extra_cnt; |
5795bf59 | 39 | if (preserve_xattrs) |
cc3e685d WD |
40 | diff --git a/configure.in b/configure.in |
41 | --- a/configure.in | |
42 | +++ b/configure.in | |
43 | @@ -551,7 +551,7 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd strdup chown chmod lchmod mknod mkfifo \ | |
31611b92 WD |
44 | memmove lchown vsnprintf snprintf vasprintf asprintf setsid glob strpbrk \ |
45 | strlcat strlcpy strtol mallinfo getgroups setgroups geteuid getegid \ | |
46 | setlocale setmode open64 lseek64 mkstemp64 mtrace va_copy __va_copy \ | |
80c89075 WD |
47 | - strerror putenv iconv_open locale_charset nl_langinfo getxattr \ |
48 | + chflags strerror putenv iconv_open locale_charset nl_langinfo getxattr \ | |
7c4c2959 | 49 | extattr_get_link sigaction sigprocmask setattrlist) |
31611b92 | 50 | |
4c15e800 | 51 | dnl cygwin iconv.h defines iconv_open as libiconv_open |
cc3e685d WD |
52 | diff --git a/flist.c b/flist.c |
53 | --- a/flist.c | |
54 | +++ b/flist.c | |
790ba11a WD |
55 | @@ -50,6 +50,7 @@ extern int preserve_links; |
56 | extern int preserve_hard_links; | |
57 | extern int preserve_devices; | |
31611b92 | 58 | extern int preserve_specials; |
790ba11a | 59 | +extern int fileflags_ndx; |
898a2112 WD |
60 | extern int uid_ndx; |
61 | extern int gid_ndx; | |
790ba11a | 62 | extern int eol_nulls; |
f2863bc0 | 63 | @@ -344,6 +345,9 @@ static void send_file_entry(int f, struct file_struct *file, int ndx, int first_ |
7e27b6c0 | 64 | { |
31611b92 WD |
65 | static time_t modtime; |
66 | static mode_t mode; | |
67 | +#ifdef SUPPORT_FLAGS | |
68 | + static uint32 fileflags; | |
69 | +#endif | |
6240d1e4 | 70 | #ifdef SUPPORT_HARD_LINKS |
31611b92 | 71 | static int64 dev; |
6240d1e4 | 72 | #endif |
a5e6228a | 73 | @@ -403,6 +407,14 @@ static void send_file_entry(int f, struct file_struct *file, int ndx, int first_ |
99650e0d | 74 | xflags |= XMIT_SAME_MODE; |
31611b92 WD |
75 | else |
76 | mode = file->mode; | |
77 | +#ifdef SUPPORT_FLAGS | |
a5e6228a WD |
78 | + if (fileflags_ndx) { |
79 | + if (F_FFLAGS(file) == fileflags) | |
80 | + xflags |= XMIT_SAME_FLAGS; | |
81 | + else | |
82 | + fileflags = F_FFLAGS(file); | |
83 | + } | |
31611b92 | 84 | +#endif |
99650e0d | 85 | |
2ad6fab3 WD |
86 | if ((preserve_devices && IS_DEVICE(mode)) |
87 | || (preserve_specials && IS_SPECIAL(mode))) { | |
a5e6228a | 88 | @@ -522,6 +534,10 @@ static void send_file_entry(int f, struct file_struct *file, int ndx, int first_ |
82c2230a | 89 | } |
99650e0d | 90 | if (!(xflags & XMIT_SAME_MODE)) |
31611b92 WD |
91 | write_int(f, to_wire_mode(mode)); |
92 | +#ifdef SUPPORT_FLAGS | |
8871c12a | 93 | + if (fileflags_ndx && !(xflags & XMIT_SAME_FLAGS)) |
31611b92 WD |
94 | + write_int(f, (int)fileflags); |
95 | +#endif | |
99650e0d | 96 | if (uid_ndx && !(xflags & XMIT_SAME_UID)) { |
caf38d8d WD |
97 | if (protocol_version < 30) |
98 | write_int(f, uid); | |
a5e6228a | 99 | @@ -610,6 +626,9 @@ static struct file_struct *recv_file_entry(struct file_list *flist, |
31611b92 | 100 | { |
82c2230a | 101 | static int64 modtime; |
31611b92 WD |
102 | static mode_t mode; |
103 | +#ifdef SUPPORT_FLAGS | |
8871c12a | 104 | + static uint32 fileflags; |
31611b92 | 105 | +#endif |
6240d1e4 | 106 | #ifdef SUPPORT_HARD_LINKS |
31611b92 | 107 | static int64 dev; |
6240d1e4 | 108 | #endif |
a5e6228a WD |
109 | @@ -744,6 +763,10 @@ static struct file_struct *recv_file_entry(struct file_list *flist, |
110 | ||
31611b92 WD |
111 | if (chmod_modes && !S_ISLNK(mode)) |
112 | mode = tweak_mode(mode, chmod_modes); | |
113 | +#ifdef SUPPORT_FLAGS | |
8871c12a | 114 | + if (fileflags_ndx && !(xflags & XMIT_SAME_FLAGS)) |
31611b92 WD |
115 | + fileflags = (uint32)read_int(f); |
116 | +#endif | |
117 | ||
898a2112 | 118 | if (uid_ndx && !(xflags & XMIT_SAME_UID)) { |
caf38d8d | 119 | if (protocol_version < 30) |
a5e6228a | 120 | @@ -865,6 +888,10 @@ static struct file_struct *recv_file_entry(struct file_list *flist, |
1aa236e1 WD |
121 | OPT_EXTRA(file, 0)->unum = (uint32)(file_length >> 32); |
122 | } | |
31611b92 WD |
123 | file->mode = mode; |
124 | +#ifdef SUPPORT_FLAGS | |
898a2112 | 125 | + if (fileflags_ndx) |
70891d26 | 126 | + F_FFLAGS(file) = fileflags; |
31611b92 | 127 | +#endif |
898a2112 | 128 | if (uid_ndx) |
fc068916 | 129 | F_OWNER(file) = uid; |
898a2112 | 130 | if (gid_ndx) { |
a5e6228a | 131 | @@ -1199,6 +1226,10 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, |
1aa236e1 WD |
132 | OPT_EXTRA(file, 0)->unum = (uint32)(st.st_size >> 32); |
133 | } | |
31611b92 WD |
134 | file->mode = st.st_mode; |
135 | +#ifdef SUPPORT_FLAGS | |
898a2112 | 136 | + if (fileflags_ndx) |
70891d26 | 137 | + F_FFLAGS(file) = st.st_flags; |
31611b92 | 138 | +#endif |
898a2112 | 139 | if (uid_ndx) |
fc068916 | 140 | F_OWNER(file) = st.st_uid; |
898a2112 | 141 | if (gid_ndx) |
cc3e685d WD |
142 | diff --git a/generator.c b/generator.c |
143 | --- a/generator.c | |
144 | +++ b/generator.c | |
a5e6228a WD |
145 | @@ -122,6 +122,7 @@ static const char *solo_file = NULL; |
146 | #define DEL_FOR_SYMLINK (1<<5) /* making room for a replacement symlink */ | |
147 | #define DEL_FOR_DEVICE (1<<6) /* making room for a replacement device */ | |
148 | #define DEL_FOR_SPECIAL (1<<7) /* making room for a replacement special */ | |
149 | +#define DEL_AN_IMMUTABLE (1<<8) /* item has an immutable flag set */ | |
f90a882e | 150 | |
a5e6228a WD |
151 | #define DEL_MAKE_ROOM (DEL_FOR_FILE|DEL_FOR_DIR|DEL_FOR_SYMLINK|DEL_FOR_DEVICE|DEL_FOR_SPECIAL) |
152 | ||
153 | @@ -161,6 +162,10 @@ static enum delret delete_item(char *fbuf, int mode, int flags) | |
87d0091c | 154 | |
a5e6228a WD |
155 | if (!am_root && !(mode & S_IWUSR) && flags & DEL_OWNED_BY_US) |
156 | do_chmod(fbuf, mode |= S_IWUSR); | |
31611b92 | 157 | +#ifdef SUPPORT_FLAGS |
a5e6228a WD |
158 | + if (fileflags_ndx && flags & DEL_AN_IMMUTABLE) |
159 | + make_mutable(fbuf, mode, NODELETE_FLAGS); | |
31611b92 | 160 | +#endif |
a5e6228a | 161 | |
d16b5fd6 WD |
162 | if (S_ISDIR(mode) && !(flags & DEL_DIR_IS_EMPTY)) { |
163 | ignore_perishable = 1; | |
a5e6228a WD |
164 | @@ -282,6 +287,14 @@ static enum delret delete_dir_contents(char *fname, int flags) |
165 | flags |= DEL_OWNED_BY_US; | |
166 | else | |
167 | flags &= ~DEL_OWNED_BY_US; | |
168 | +#ifdef SUPPORT_FLAGS | |
169 | + if (fileflags_ndx) { | |
170 | + if (F_FFLAGS(fp) & NODELETE_FLAGS) | |
171 | + flags |= DEL_AN_IMMUTABLE; | |
172 | + else | |
173 | + flags &= ~DEL_AN_IMMUTABLE; | |
174 | + } | |
175 | +#endif | |
176 | /* Save stack by recursing to ourself directly. */ | |
177 | if (S_ISDIR(fp->mode)) { | |
178 | if (!am_root && !(fp->mode & S_IWUSR) && flags & DEL_OWNED_BY_US) | |
179 | @@ -341,15 +354,22 @@ static int flush_delete_delay(void) | |
180 | ||
181 | static int remember_delete(struct file_struct *file, const char *fname, int flags) | |
182 | { | |
183 | - const char *plus = (!am_root && !(file->mode & S_IWUSR) && flags & DEL_OWNED_BY_US) | |
184 | - ? "+" : ""; | |
185 | + char buf[16], *bp = buf; | |
186 | int len; | |
d4dd2dd5 | 187 | |
a5e6228a WD |
188 | + if (!am_root && !(file->mode & S_IWUSR) && flags & DEL_OWNED_BY_US) |
189 | + *bp++ = '+'; | |
190 | +#ifdef SUPPORT_FLAGS | |
191 | + if (flags & DEL_AN_IMMUTABLE) | |
192 | + *bp++ = '-'; | |
193 | +#endif | |
194 | + *bp = '\0'; | |
195 | + | |
ee76479d WD |
196 | while (1) { |
197 | len = snprintf(deldelay_buf + deldelay_cnt, | |
a5e6228a WD |
198 | deldelay_size - deldelay_cnt, |
199 | "%s%x %s%c", | |
200 | - plus, (int)file->mode, fname, '\0'); | |
201 | + buf, (int)file->mode, fname, '\0'); | |
ee76479d WD |
202 | if ((deldelay_cnt += len) <= deldelay_size) |
203 | break; | |
204 | if (deldelay_fd < 0 && !start_delete_delay_temp()) | |
a5e6228a | 205 | @@ -362,10 +382,10 @@ static int remember_delete(struct file_struct *file, const char *fname, int flag |
ee76479d WD |
206 | return 1; |
207 | } | |
208 | ||
a5e6228a WD |
209 | -static int read_delay_line(char *buf, int *own_flag_p) |
210 | +static int read_delay_line(char *buf, int *flags_p) | |
ee76479d WD |
211 | { |
212 | static int read_pos = 0; | |
a5e6228a WD |
213 | - int j, len, mode; |
214 | + int j, len, mode, flags = 0; | |
215 | char *bp, *past_space; | |
ee76479d | 216 | |
a5e6228a WD |
217 | while (1) { |
218 | @@ -405,9 +425,15 @@ static int read_delay_line(char *buf, int *own_flag_p) | |
ee76479d | 219 | bp = deldelay_buf + read_pos; |
a5e6228a WD |
220 | if (*bp == '+') { |
221 | bp++; | |
222 | - *own_flag_p = DEL_OWNED_BY_US; | |
223 | - } else | |
224 | - *own_flag_p = 0; | |
225 | + flags |= DEL_OWNED_BY_US; | |
226 | + } | |
227 | +#ifdef SUPPORT_FLAGS | |
228 | + if (*bp == '-') { | |
229 | + bp++; | |
230 | + flags |= DEL_AN_IMMUTABLE; | |
231 | + } | |
232 | +#endif | |
233 | + *flags_p = flags; | |
ee76479d | 234 | |
a5e6228a | 235 | if (sscanf(bp, "%x ", &mode) != 1) { |
ee76479d | 236 | invalid_data: |
a5e6228a | 237 | @@ -432,15 +458,15 @@ static int read_delay_line(char *buf, int *own_flag_p) |
ee76479d WD |
238 | |
239 | static void do_delayed_deletions(char *delbuf) | |
240 | { | |
a5e6228a WD |
241 | - int mode, own_flag; |
242 | + int mode, flags; | |
ee76479d WD |
243 | |
244 | if (deldelay_fd >= 0) { | |
245 | if (deldelay_cnt && !flush_delete_delay()) | |
246 | return; | |
247 | lseek(deldelay_fd, 0, 0); | |
248 | } | |
a5e6228a WD |
249 | - while ((mode = read_delay_line(delbuf, &own_flag)) >= 0) |
250 | - delete_item(delbuf, mode, own_flag | DEL_RECURSE); | |
251 | + while ((mode = read_delay_line(delbuf, &flags)) >= 0) | |
252 | + delete_item(delbuf, mode, DEL_RECURSE | flags); | |
ee76479d WD |
253 | if (deldelay_fd >= 0) |
254 | close(deldelay_fd); | |
255 | } | |
a5e6228a | 256 | @@ -503,6 +529,9 @@ static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev) |
f90a882e | 257 | } |
a5e6228a WD |
258 | if (flist_find(cur_flist, fp) < 0) { |
259 | int flags = DEL_RECURSE | |
260 | +#ifdef SUPPORT_FLAGS | |
261 | + | (fileflags_ndx && F_FFLAGS(fp) & NODELETE_FLAGS ? DEL_AN_IMMUTABLE : 0) | |
262 | +#endif | |
263 | | (!uid_ndx || (uid_t)F_OWNER(fp) == our_uid ? DEL_OWNED_BY_US : 0); | |
264 | f_name(fp, delbuf); | |
265 | if (delete_during == 2) { | |
266 | @@ -1316,6 +1345,10 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, | |
f90a882e | 267 | |
a5e6228a WD |
268 | if (statret == 0 && sx.st.st_uid == our_uid) |
269 | del_opts |= DEL_OWNED_BY_US; | |
270 | +#ifdef SUPPORT_FLAGS | |
271 | + if (statret == 0 && fileflags_ndx && sx.st.st_flags & NODELETE_FLAGS) | |
272 | + del_opts |= DEL_AN_IMMUTABLE; | |
273 | +#endif | |
274 | ||
275 | if (S_ISDIR(file->mode)) { | |
276 | if (!implied_dirs && file->flags & FLAG_IMPLIED_DIR) | |
cc3e685d WD |
277 | diff --git a/options.c b/options.c |
278 | --- a/options.c | |
279 | +++ b/options.c | |
f2863bc0 | 280 | @@ -52,6 +52,7 @@ int preserve_hard_links = 0; |
ffc18846 | 281 | int preserve_acls = 0; |
5795bf59 | 282 | int preserve_xattrs = 0; |
31611b92 | 283 | int preserve_perms = 0; |
5e3c6c93 | 284 | +int preserve_fileflags = 0; |
31611b92 WD |
285 | int preserve_executability = 0; |
286 | int preserve_devices = 0; | |
287 | int preserve_specials = 0; | |
f2863bc0 | 288 | @@ -223,6 +224,7 @@ static void print_rsync_version(enum logcode f) |
31611b92 | 289 | char const *links = "no "; |
58b399b9 | 290 | char const *iconv = "no "; |
31611b92 | 291 | char const *ipv6 = "no "; |
8871c12a | 292 | + char const *fileflags = "no "; |
31611b92 WD |
293 | STRUCT_STAT *dumstat; |
294 | ||
ac2da598 | 295 | #if SUBPROTOCOL_VERSION != 0 |
f2863bc0 | 296 | @@ -252,6 +254,9 @@ static void print_rsync_version(enum logcode f) |
58b399b9 WD |
297 | #ifdef ICONV_OPTION |
298 | iconv = ""; | |
31611b92 | 299 | #endif |
31611b92 | 300 | +#ifdef SUPPORT_FLAGS |
5e3c6c93 | 301 | + fileflags = ""; |
31611b92 | 302 | +#endif |
ac2da598 WD |
303 | |
304 | rprintf(f, "%s version %s protocol version %d%s\n", | |
305 | RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION, subprotocol); | |
f2863bc0 | 306 | @@ -265,8 +270,8 @@ static void print_rsync_version(enum logcode f) |
5e3c6c93 WD |
307 | (int)(sizeof (int64) * 8)); |
308 | rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n", | |
309 | got_socketpair, hardlinks, links, ipv6, have_inplace); | |
58b399b9 WD |
310 | - rprintf(f, " %sappend, %sACLs, %sxattrs, %siconv\n", |
311 | - have_inplace, acls, xattrs, iconv); | |
312 | + rprintf(f, " %sappend, %sACLs, %sxattrs, %siconv, %sfile-flags\n", | |
313 | + have_inplace, acls, xattrs, iconv, fileflags); | |
5e3c6c93 | 314 | |
31611b92 | 315 | #ifdef MAINTAINER_MODE |
5e3c6c93 | 316 | rprintf(f, "Panic Action: \"%s\"\n", get_panic_action()); |
f2863bc0 | 317 | @@ -333,6 +338,7 @@ void usage(enum logcode F) |
31611b92 WD |
318 | rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n"); |
319 | rprintf(F," -H, --hard-links preserve hard links\n"); | |
320 | rprintf(F," -p, --perms preserve permissions\n"); | |
5e3c6c93 | 321 | + rprintf(F," --fileflags preserve file-flags\n"); |
31611b92 | 322 | rprintf(F," -E, --executability preserve the file's executability\n"); |
063cf77b | 323 | rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n"); |
ffc18846 | 324 | #ifdef SUPPORT_ACLS |
f2863bc0 | 325 | @@ -473,6 +479,8 @@ static struct poptOption long_options[] = { |
31611b92 WD |
326 | {"perms", 'p', POPT_ARG_VAL, &preserve_perms, 1, 0, 0 }, |
327 | {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, | |
328 | {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, | |
5e3c6c93 WD |
329 | + {"fileflags", 0, POPT_ARG_VAL, &preserve_fileflags, 1, 0, 0 }, |
330 | + {"no-fileflags", 0, POPT_ARG_VAL, &preserve_fileflags, 0, 0, 0 }, | |
31611b92 | 331 | {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 }, |
ffc18846 WD |
332 | {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 }, |
333 | {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
f2863bc0 | 334 | @@ -1289,6 +1297,15 @@ int parse_arguments(int *argc_p, const char ***argv_p, int frommain) |
31611b92 WD |
335 | } |
336 | #endif | |
337 | ||
338 | +#ifndef SUPPORT_FLAGS | |
5e3c6c93 | 339 | + if (preserve_fileflags) { |
31611b92 | 340 | + snprintf(err_buf, sizeof err_buf, |
a5e6228a | 341 | + "the --fileflags option is not supported on this %s\n", |
31611b92 WD |
342 | + am_server ? "server" : "client"); |
343 | + return 0; | |
344 | + } | |
345 | +#endif | |
346 | + | |
347 | if (write_batch && read_batch) { | |
348 | snprintf(err_buf, sizeof err_buf, | |
349 | "--write-batch and --read-batch can not be used together\n"); | |
a5e6228a | 350 | @@ -1804,6 +1821,9 @@ void server_options(char **args, int *argc_p) |
31611b92 WD |
351 | if (xfer_dirs && !recurse && delete_mode && am_sender) |
352 | args[ac++] = "--no-r"; | |
353 | ||
5e3c6c93 | 354 | + if (preserve_fileflags) |
a5e6228a | 355 | + args[ac++] = "--fileflags"; |
31611b92 WD |
356 | + |
357 | if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) { | |
358 | if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0) | |
359 | goto oom; | |
cc3e685d WD |
360 | diff --git a/rsync.c b/rsync.c |
361 | --- a/rsync.c | |
362 | +++ b/rsync.c | |
52e09c4e | 363 | @@ -32,6 +32,7 @@ extern int dry_run; |
ffc18846 | 364 | extern int preserve_acls; |
5795bf59 | 365 | extern int preserve_xattrs; |
31611b92 | 366 | extern int preserve_perms; |
5e3c6c93 | 367 | +extern int preserve_fileflags; |
31611b92 WD |
368 | extern int preserve_executability; |
369 | extern int preserve_times; | |
9c25eef5 | 370 | extern int am_root; |
a5e6228a | 371 | @@ -338,6 +339,41 @@ mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms, |
f90a882e WD |
372 | return new_mode; |
373 | } | |
374 | ||
375 | +#ifdef SUPPORT_FLAGS | |
376 | +/* Set a file's st_flags. */ | |
377 | +static int set_fileflags(const char *fname, uint32 fileflags) | |
378 | +{ | |
379 | + if (do_chflags(fname, fileflags) != 0) { | |
cc3e685d | 380 | + rsyserr(FERROR_XFER, errno, |
f90a882e WD |
381 | + "failed to set file flags on %s", |
382 | + full_fname(fname)); | |
383 | + return 0; | |
384 | + } | |
385 | + | |
386 | + return 1; | |
387 | +} | |
388 | + | |
389 | +/* Remove immutable flags from an object, so it can be altered/removed. */ | |
2ad6fab3 | 390 | +void make_mutable(const char *fname, mode_t mode, uint32 fileflags) |
f90a882e | 391 | +{ |
a5e6228a | 392 | + if (S_ISLNK(mode)) |
f90a882e WD |
393 | + return; |
394 | + | |
395 | + if (fileflags & NOCHANGE_FLAGS) | |
396 | + set_fileflags(fname, fileflags & ~NOCHANGE_FLAGS); | |
397 | +} | |
398 | + | |
399 | +/* Undo a prior make_mutable() call. */ | |
2ad6fab3 | 400 | +void undo_make_mutable(const char *fname, mode_t mode, uint32 fileflags) |
f90a882e | 401 | +{ |
a5e6228a | 402 | + if (S_ISLNK(mode)) |
f90a882e WD |
403 | + return; |
404 | + | |
405 | + if (fileflags & NOCHANGE_FLAGS) | |
406 | + set_fileflags(fname, fileflags); | |
407 | +} | |
408 | +#endif | |
409 | + | |
52e09c4e | 410 | int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp, |
5795bf59 | 411 | const char *fnamecmp, int flags) |
f90a882e | 412 | { |
a5e6228a | 413 | @@ -469,6 +505,15 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp, |
31611b92 WD |
414 | } |
415 | #endif | |
416 | ||
417 | +#ifdef SUPPORT_FLAGS | |
7d006b5b WD |
418 | + if (preserve_fileflags && !S_ISLNK(sxp->st.st_mode) |
419 | + && sxp->st.st_flags != F_FFLAGS(file)) { | |
420 | + if (!set_fileflags(fname, F_FFLAGS(file))) | |
31611b92 | 421 | + return 0; |
31611b92 WD |
422 | + updated = 1; |
423 | + } | |
424 | +#endif | |
425 | + | |
426 | if (verbose > 1 && flags & ATTRS_REPORT) { | |
ff318e90 WD |
427 | if (updated) |
428 | rprintf(FCLIENT, "%s\n", fname); | |
a5e6228a | 429 | @@ -530,6 +575,10 @@ int finish_transfer(const char *fname, const char *fnametmp, |
5795bf59 | 430 | set_file_attrs(fnametmp, file, NULL, fnamecmp, |
f90a882e | 431 | ok_to_set_time ? 0 : ATTRS_SKIP_MTIME); |
31611b92 WD |
432 | |
433 | +#ifdef SUPPORT_FLAGS | |
a5e6228a WD |
434 | + if (preserve_fileflags) |
435 | + make_mutable(fnametmp, file->mode, F_FFLAGS(file)); | |
31611b92 | 436 | +#endif |
f90a882e WD |
437 | /* move tmp file over real file */ |
438 | if (verbose > 2) | |
439 | rprintf(FINFO, "renaming %s to %s\n", fnametmp, fname); | |
a5e6228a | 440 | @@ -547,6 +596,10 @@ int finish_transfer(const char *fname, const char *fnametmp, |
f90a882e WD |
441 | } |
442 | if (ret == 0) { | |
443 | /* The file was moved into place (not copied), so it's done. */ | |
31611b92 | 444 | +#ifdef SUPPORT_FLAGS |
a5e6228a WD |
445 | + if (preserve_fileflags) |
446 | + undo_make_mutable(fname, file->mode, F_FFLAGS(file)); | |
31611b92 | 447 | +#endif |
4c15e800 | 448 | return 1; |
f90a882e WD |
449 | } |
450 | /* The file was copied, so tweak the perms of the copied file. If it | |
cc3e685d WD |
451 | diff --git a/rsync.h b/rsync.h |
452 | --- a/rsync.h | |
453 | +++ b/rsync.h | |
454 | @@ -60,6 +60,7 @@ | |
caf38d8d | 455 | #define XMIT_RDEV_MINOR_8_pre30 (1<<11) /* protocols 28 - 29 */ |
9c25eef5 WD |
456 | #define XMIT_GROUP_NAME_FOLLOWS (1<<11) /* protocols 30 - now */ |
457 | #define XMIT_HLINK_FIRST (1<<12) /* protocols 30 - now (HLINKED files only) */ | |
458 | +#define XMIT_SAME_FLAGS (1<<14) /* protocols ?? - now */ | |
31611b92 WD |
459 | |
460 | /* These flags are used in the live flist data. */ | |
461 | ||
a5e6228a | 462 | @@ -451,6 +452,21 @@ typedef unsigned int size_t; |
7e27b6c0 | 463 | #endif |
6e6f514c WD |
464 | #endif |
465 | ||
466 | +#ifdef HAVE_CHFLAGS | |
467 | +#define SUPPORT_FLAGS 1 | |
468 | +#endif | |
a5e6228a WD |
469 | + |
470 | +#ifdef SUPPORT_FLAGS | |
471 | +#ifndef UF_NOUNLINK | |
472 | +#define UF_NOUNLINK 0 | |
473 | +#endif | |
474 | +#ifndef SF_NOUNLINK | |
475 | +#define SF_NOUNLINK 0 | |
476 | +#endif | |
477 | +#define NODELETE_FLAGS (UF_IMMUTABLE|UF_NOUNLINK|SF_IMMUTABLE|SF_NOUNLINK) | |
478 | +#define NOCHANGE_FLAGS (NODELETE_FLAGS|UF_APPEND|SF_APPEND) | |
479 | +#endif | |
6e6f514c WD |
480 | + |
481 | /* Find a variable that is either exactly 32-bits or longer. | |
482 | * If some code depends on 32-bit truncation, it will need to | |
483 | * take special action in a "#if SIZEOF_INT32 > 4" section. */ | |
a5e6228a | 484 | @@ -619,6 +635,7 @@ extern int file_extra_cnt; |
9c25eef5 | 485 | extern int inc_recurse; |
898a2112 WD |
486 | extern int uid_ndx; |
487 | extern int gid_ndx; | |
488 | +extern int fileflags_ndx; | |
489 | extern int acls_ndx; | |
490 | extern int xattrs_ndx; | |
fdf967c7 | 491 | |
a5e6228a | 492 | @@ -656,6 +673,7 @@ extern int xattrs_ndx; |
1aa236e1 | 493 | /* When the associated option is on, all entries will have these present: */ |
898a2112 WD |
494 | #define F_OWNER(f) REQ_EXTRA(f, uid_ndx)->unum |
495 | #define F_GROUP(f) REQ_EXTRA(f, gid_ndx)->unum | |
496 | +#define F_FFLAGS(f) REQ_EXTRA(f, fileflags_ndx)->unum | |
497 | #define F_ACL(f) REQ_EXTRA(f, acls_ndx)->num | |
498 | #define F_XATTR(f) REQ_EXTRA(f, xattrs_ndx)->num | |
d4dd2dd5 | 499 | #define F_NDX(f) REQ_EXTRA(f, unsort_ndx)->num |
cc3e685d WD |
500 | diff --git a/rsync.yo b/rsync.yo |
501 | --- a/rsync.yo | |
502 | +++ b/rsync.yo | |
503 | @@ -338,6 +338,7 @@ to the detailed description below for a complete description. verb( | |
1ed0b5c9 WD |
504 | -K, --keep-dirlinks treat symlinked dir on receiver as dir |
505 | -H, --hard-links preserve hard links | |
31611b92 | 506 | -p, --perms preserve permissions |
a5e6228a | 507 | + --fileflags preserve file-flags |
1ed0b5c9 | 508 | -E, --executability preserve executability |
063cf77b | 509 | --chmod=CHMOD affect file and/or directory permissions |
ffc18846 | 510 | -A, --acls preserve ACLs (implies -p) |
a5e6228a | 511 | @@ -540,7 +541,8 @@ specified, in which case bf(-r) is not implied. |
31611b92 WD |
512 | |
513 | Note that bf(-a) bf(does not preserve hardlinks), because | |
514 | finding multiply-linked files is expensive. You must separately | |
515 | -specify bf(-H). | |
a5e6228a WD |
516 | +specify bf(-H). Note also that for backward compatibility, bf(-a) |
517 | +currently does bf(not) imply the bf(--fileflags) option. | |
31611b92 WD |
518 | |
519 | dit(--no-OPTION) You may turn off one or more implied options by prefixing | |
520 | the option name with "no-". Not all options may be prefixed with a "no-": | |
a5e6228a | 521 | @@ -922,6 +924,13 @@ super-user copies all namespaces except system.*. A normal user only copies |
c8a8b4a7 WD |
522 | the user.* namespace. To be able to backup and restore non-user namespaces as |
523 | a normal user, see the bf(--fake-super) option. | |
31611b92 | 524 | |
a5e6228a | 525 | +dit(bf(--fileflags)) This option causes rsync to update the file-flags |
f90a882e | 526 | +to be the same as the source file, if your OS supports the bf(chflags)(2) |
31611b92 WD |
527 | +system call. In any case, an attempt is made to remove flags that would |
528 | +prevent a file to be altered. Some flags can only be altered by the | |
529 | +super-user and can only be unset below a certain secure-level (usually | |
530 | +single-user mode). | |
531 | + | |
532 | dit(bf(--chmod)) This option tells rsync to apply one or more | |
533 | comma-separated "chmod" strings to the permission of the files in the | |
534 | transfer. The resulting value is treated as though it was the permissions | |
cc3e685d WD |
535 | diff --git a/syscall.c b/syscall.c |
536 | --- a/syscall.c | |
537 | +++ b/syscall.c | |
a5e6228a | 538 | @@ -174,6 +174,15 @@ int do_chmod(const char *path, mode_t mode) |
31611b92 WD |
539 | } |
540 | #endif | |
541 | ||
542 | +#ifdef SUPPORT_FLAGS | |
543 | +int do_chflags(const char *path, u_long flags) | |
544 | +{ | |
545 | + if (dry_run) return 0; | |
546 | + RETURN_ERROR_IF_RO_OR_LO; | |
547 | + return chflags(path, flags); | |
548 | +} | |
549 | +#endif | |
550 | + | |
551 | int do_rename(const char *fname1, const char *fname2) | |
552 | { | |
553 | if (dry_run) return 0; |