Commit | Line | Data |
---|---|---|
31611b92 | 1 | This patch provides --flags, which preserves the st_flags 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 | |
5bafda30 WD |
11 | TODO: fix --delete-delay to work with --flags option. |
12 | ||
fdf967c7 WD |
13 | --- old/compat.c |
14 | +++ new/compat.c | |
ac2da598 | 15 | @@ -94,6 +94,8 @@ void setup_protocol(int f_out,int f_in) |
7e27b6c0 | 16 | preserve_uid = ++file_extra_cnt; |
fdf967c7 | 17 | if (preserve_gid) |
7e27b6c0 | 18 | preserve_gid = ++file_extra_cnt; |
fdf967c7 | 19 | + if (preserve_fileflags) |
7e27b6c0 | 20 | + preserve_fileflags = ++file_extra_cnt; |
ffc18846 WD |
21 | if (preserve_acls && !am_sender) |
22 | preserve_acls = ++file_extra_cnt; | |
5795bf59 | 23 | if (preserve_xattrs) |
31611b92 WD |
24 | --- old/configure.in |
25 | +++ new/configure.in | |
82c2230a | 26 | @@ -560,7 +560,7 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd strd |
31611b92 WD |
27 | memmove lchown vsnprintf snprintf vasprintf asprintf setsid glob strpbrk \ |
28 | strlcat strlcpy strtol mallinfo getgroups setgroups geteuid getegid \ | |
29 | setlocale setmode open64 lseek64 mkstemp64 mtrace va_copy __va_copy \ | |
30 | - strerror putenv iconv_open locale_charset nl_langinfo \ | |
31 | + chflags strerror putenv iconv_open locale_charset nl_langinfo \ | |
32 | sigaction sigprocmask) | |
33 | ||
34 | AC_CHECK_FUNCS(getpgrp tcgetpgrp) | |
35 | --- old/flist.c | |
36 | +++ new/flist.c | |
82c2230a | 37 | @@ -49,6 +49,7 @@ extern int preserve_links; |
31611b92 WD |
38 | extern int preserve_hard_links; |
39 | extern int preserve_devices; | |
40 | extern int preserve_specials; | |
5e3c6c93 | 41 | +extern int preserve_fileflags; |
31611b92 WD |
42 | extern int preserve_uid; |
43 | extern int preserve_gid; | |
44 | extern int relative_paths; | |
58b399b9 | 45 | @@ -340,6 +341,9 @@ static void send_file_entry(int f, struc |
7e27b6c0 | 46 | { |
31611b92 WD |
47 | static time_t modtime; |
48 | static mode_t mode; | |
49 | +#ifdef SUPPORT_FLAGS | |
50 | + static uint32 fileflags; | |
51 | +#endif | |
52 | static int64 dev; | |
53 | static dev_t rdev; | |
54 | static uint32 rdev_major; | |
58b399b9 | 55 | @@ -388,6 +392,12 @@ static void send_file_entry(int f, struc |
31611b92 WD |
56 | flags |= XMIT_SAME_MODE; |
57 | else | |
58 | mode = file->mode; | |
59 | +#ifdef SUPPORT_FLAGS | |
7d006b5b | 60 | + if (F_FFLAGS(file) == fileflags) |
31611b92 WD |
61 | + flags |= XMIT_SAME_FLAGS; |
62 | + else | |
7d006b5b | 63 | + fileflags = F_FFLAGS(file); |
31611b92 WD |
64 | +#endif |
65 | if ((preserve_devices && IS_DEVICE(mode)) | |
66 | || (preserve_specials && IS_SPECIAL(mode))) { | |
67 | if (protocol_version < 28) { | |
58b399b9 | 68 | @@ -505,6 +515,10 @@ static void send_file_entry(int f, struc |
82c2230a | 69 | } |
31611b92 WD |
70 | if (!(flags & XMIT_SAME_MODE)) |
71 | write_int(f, to_wire_mode(mode)); | |
72 | +#ifdef SUPPORT_FLAGS | |
5e3c6c93 | 73 | + if (preserve_fileflags && !(flags & XMIT_SAME_FLAGS)) |
31611b92 WD |
74 | + write_int(f, (int)fileflags); |
75 | +#endif | |
76 | if (preserve_uid && !(flags & XMIT_SAME_UID)) { | |
caf38d8d WD |
77 | if (protocol_version < 30) |
78 | write_int(f, uid); | |
58b399b9 | 79 | @@ -593,6 +607,9 @@ static struct file_struct *recv_file_ent |
31611b92 | 80 | { |
82c2230a | 81 | static int64 modtime; |
31611b92 WD |
82 | static mode_t mode; |
83 | +#ifdef SUPPORT_FLAGS | |
84 | + static uint32 fileflags; | |
85 | +#endif | |
86 | static int64 dev; | |
87 | static dev_t rdev; | |
88 | static uint32 rdev_major; | |
58b399b9 | 89 | @@ -725,9 +742,12 @@ static struct file_struct *recv_file_ent |
82c2230a | 90 | } |
31611b92 WD |
91 | if (!(flags & XMIT_SAME_MODE)) |
92 | mode = from_wire_mode(read_int(f)); | |
93 | - | |
94 | if (chmod_modes && !S_ISLNK(mode)) | |
95 | mode = tweak_mode(mode, chmod_modes); | |
96 | +#ifdef SUPPORT_FLAGS | |
5e3c6c93 | 97 | + if (preserve_fileflags && !(flags & XMIT_SAME_FLAGS)) |
31611b92 WD |
98 | + fileflags = (uint32)read_int(f); |
99 | +#endif | |
100 | ||
fc068916 | 101 | if (preserve_uid && !(flags & XMIT_SAME_UID)) { |
caf38d8d | 102 | if (protocol_version < 30) |
58b399b9 | 103 | @@ -846,6 +866,10 @@ static struct file_struct *recv_file_ent |
1aa236e1 WD |
104 | OPT_EXTRA(file, 0)->unum = (uint32)(file_length >> 32); |
105 | } | |
31611b92 WD |
106 | file->mode = mode; |
107 | +#ifdef SUPPORT_FLAGS | |
70891d26 WD |
108 | + if (preserve_fileflags) |
109 | + F_FFLAGS(file) = fileflags; | |
31611b92 | 110 | +#endif |
70891d26 | 111 | if (preserve_uid) |
fc068916 | 112 | F_OWNER(file) = uid; |
70891d26 | 113 | if (preserve_gid) |
58b399b9 | 114 | @@ -1159,6 +1183,10 @@ struct file_struct *make_file(const char |
1aa236e1 WD |
115 | OPT_EXTRA(file, 0)->unum = (uint32)(st.st_size >> 32); |
116 | } | |
31611b92 WD |
117 | file->mode = st.st_mode; |
118 | +#ifdef SUPPORT_FLAGS | |
70891d26 WD |
119 | + if (preserve_fileflags) |
120 | + F_FFLAGS(file) = st.st_flags; | |
31611b92 | 121 | +#endif |
70891d26 | 122 | if (preserve_uid) |
fc068916 | 123 | F_OWNER(file) = st.st_uid; |
70891d26 | 124 | if (preserve_gid) |
31611b92 WD |
125 | --- old/generator.c |
126 | +++ new/generator.c | |
58b399b9 | 127 | @@ -115,6 +115,14 @@ static int dir_tweaking; |
ffc18846 WD |
128 | static int need_retouch_dir_times; |
129 | static const char *solo_file = NULL; | |
f90a882e WD |
130 | |
131 | +#ifdef SUPPORT_FLAGS | |
7d006b5b WD |
132 | +#define FF_PTR(p) F_FFLAGS(p) |
133 | +#define FF_STAT(s) s.st_flags | |
f90a882e | 134 | +#else |
7d006b5b WD |
135 | +#define FF_PTR(p) 0 |
136 | +#define FF_STAT(s) 0 | |
f90a882e WD |
137 | +#endif |
138 | + | |
d16b5fd6 | 139 | /* For calling delete_item() and delete_dir_contents(). */ |
87d0091c | 140 | #define DEL_RECURSE (1<<1) /* recurse */ |
d16b5fd6 | 141 | #define DEL_DIR_IS_EMPTY (1<<2) /* internal delete_FUNCTIONS use only */ |
58b399b9 | 142 | @@ -130,7 +138,6 @@ enum delret { |
87d0091c WD |
143 | /* Forward declaration for delete_item(). */ |
144 | static enum delret delete_dir_contents(char *fname, int flags); | |
f90a882e | 145 | |
87d0091c WD |
146 | - |
147 | static int is_backup_file(char *fn) | |
148 | { | |
149 | int k = strlen(fn) - backup_suffix_len; | |
58b399b9 | 150 | @@ -143,17 +150,20 @@ static int is_backup_file(char *fn) |
f813befd | 151 | * Note that fbuf must point to a MAXPATHLEN buffer if the mode indicates it's |
f90a882e WD |
152 | * a directory! (The buffer is used for recursion, but returned unchanged.) |
153 | */ | |
f813befd WD |
154 | -static enum delret delete_item(char *fbuf, int mode, char *replace, int flags) |
155 | +static enum delret delete_item(char *fbuf, int mode, uint32 fileflags, char *replace, int flags) | |
f90a882e | 156 | { |
87d0091c WD |
157 | enum delret ret; |
158 | char *what; | |
159 | int ok; | |
160 | ||
161 | if (verbose > 2) { | |
162 | - rprintf(FINFO, "delete_item(%s) mode=%o flags=%d\n", | |
f813befd | 163 | - fbuf, mode, flags); |
87d0091c | 164 | + rprintf(FINFO, "delete_item(%s) mode=%o fileflags=%o flags=%d\n", |
f813befd | 165 | + fbuf, mode, fileflags, flags); |
87d0091c WD |
166 | } |
167 | ||
31611b92 | 168 | +#ifdef SUPPORT_FLAGS |
f813befd | 169 | + make_mutable(fbuf, mode, fileflags); |
31611b92 | 170 | +#endif |
d16b5fd6 WD |
171 | if (S_ISDIR(mode) && !(flags & DEL_DIR_IS_EMPTY)) { |
172 | ignore_perishable = 1; | |
173 | /* If DEL_RECURSE is not set, this just reports emptiness. */ | |
58b399b9 | 174 | @@ -265,7 +275,7 @@ static enum delret delete_dir_contents(c |
d16b5fd6 WD |
175 | if (S_ISDIR(fp->mode) |
176 | && delete_dir_contents(fname, flags | DEL_RECURSE) != DR_SUCCESS) | |
177 | ret = DR_NOT_EMPTY; | |
178 | - if (delete_item(fname, fp->mode, NULL, flags) != DR_SUCCESS) | |
7d006b5b | 179 | + if (delete_item(fname, fp->mode, FF_PTR(fp), NULL, flags) != DR_SUCCESS) |
d16b5fd6 | 180 | ret = DR_NOT_EMPTY; |
f90a882e | 181 | } |
d16b5fd6 | 182 | |
58b399b9 | 183 | @@ -321,8 +331,9 @@ static int remember_delete(struct file_s |
ee76479d WD |
184 | |
185 | while (1) { | |
186 | len = snprintf(deldelay_buf + deldelay_cnt, | |
187 | - deldelay_size - deldelay_cnt, | |
188 | - "%x %s%c", (int)file->mode, fname, '\0'); | |
189 | + deldelay_size - deldelay_cnt, "%x %x %s%c", | |
7d006b5b | 190 | + (int)file->mode, (int)FF_PTR(file), |
ee76479d WD |
191 | + fname, '\0'); |
192 | if ((deldelay_cnt += len) <= deldelay_size) | |
193 | break; | |
194 | if (deldelay_fd < 0 && !start_delete_delay_temp()) | |
58b399b9 | 195 | @@ -335,7 +346,7 @@ static int remember_delete(struct file_s |
ee76479d WD |
196 | return 1; |
197 | } | |
198 | ||
199 | -static int read_delay_line(char *buf) | |
200 | +static int read_delay_line(char *buf, int *fileflags_p) | |
201 | { | |
202 | static int read_pos = 0; | |
203 | int j, len, mode; | |
58b399b9 | 204 | @@ -377,7 +388,7 @@ static int read_delay_line(char *buf) |
ee76479d WD |
205 | |
206 | bp = deldelay_buf + read_pos; | |
207 | ||
208 | - if (sscanf(bp, "%x ", &mode) != 1) { | |
209 | + if (sscanf(bp, "%x %x ", &mode, fileflags_p) != 2) { | |
210 | invalid_data: | |
211 | rprintf(FERROR, "ERROR: invalid data in delete-delay file.\n"); | |
212 | return -1; | |
58b399b9 | 213 | @@ -400,15 +411,15 @@ static int read_delay_line(char *buf) |
ee76479d WD |
214 | |
215 | static void do_delayed_deletions(char *delbuf) | |
216 | { | |
217 | - int mode; | |
218 | + int mode, fileflags; | |
219 | ||
220 | if (deldelay_fd >= 0) { | |
221 | if (deldelay_cnt && !flush_delete_delay()) | |
222 | return; | |
223 | lseek(deldelay_fd, 0, 0); | |
224 | } | |
225 | - while ((mode = read_delay_line(delbuf)) >= 0) | |
226 | - delete_item(delbuf, mode, NULL, DEL_RECURSE); | |
227 | + while ((mode = read_delay_line(delbuf, &fileflags)) >= 0) | |
228 | + delete_item(delbuf, mode, fileflags, NULL, DEL_RECURSE); | |
229 | if (deldelay_fd >= 0) | |
230 | close(deldelay_fd); | |
231 | } | |
58b399b9 | 232 | @@ -475,7 +486,7 @@ static void delete_in_dir(char *fbuf, st |
ee76479d WD |
233 | if (!remember_delete(fp, delbuf)) |
234 | break; | |
235 | } else | |
f813befd | 236 | - delete_item(delbuf, fp->mode, NULL, DEL_RECURSE); |
7d006b5b | 237 | + delete_item(delbuf, fp->mode, FF_PTR(fp), NULL, DEL_RECURSE); |
f90a882e WD |
238 | } |
239 | } | |
240 | ||
58b399b9 | 241 | @@ -1213,7 +1224,7 @@ static void recv_generator(char *fname, |
0461b869 | 242 | * we need to delete it. If it doesn't exist, then |
f90a882e | 243 | * (perhaps recursively) create it. */ |
ffc18846 WD |
244 | if (statret == 0 && !S_ISDIR(sx.st.st_mode)) { |
245 | - if (delete_item(fname, sx.st.st_mode, "directory", del_opts) != 0) | |
7d006b5b | 246 | + if (delete_item(fname, sx.st.st_mode, FF_STAT(sx.st), "directory", del_opts) != 0) |
f90a882e WD |
247 | return; |
248 | statret = -1; | |
249 | } | |
58b399b9 | 250 | @@ -1326,7 +1337,7 @@ static void recv_generator(char *fname, |
f90a882e WD |
251 | } |
252 | /* Not the right symlink (or not a symlink), so | |
253 | * delete it. */ | |
ffc18846 | 254 | - if (delete_item(fname, sx.st.st_mode, "symlink", del_opts) != 0) |
7d006b5b | 255 | + if (delete_item(fname, sx.st.st_mode, FF_STAT(sx.st), "symlink", del_opts) != 0) |
ffc18846 | 256 | goto cleanup; |
05031682 | 257 | } else if (basis_dir[0] != NULL) { |
ffc18846 | 258 | int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, |
58b399b9 | 259 | @@ -1403,7 +1414,7 @@ static void recv_generator(char *fname, |
05031682 | 260 | goto return_with_success; |
ffc18846 | 261 | goto cleanup; |
05031682 | 262 | } |
ffc18846 | 263 | - if (delete_item(fname, sx.st.st_mode, t, del_opts) != 0) |
7d006b5b | 264 | + if (delete_item(fname, sx.st.st_mode, FF_STAT(sx.st), t, del_opts) != 0) |
ffc18846 | 265 | goto cleanup; |
05031682 | 266 | } else if (basis_dir[0] != NULL) { |
ffc18846 | 267 | int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, |
58b399b9 | 268 | @@ -1492,7 +1503,7 @@ static void recv_generator(char *fname, |
f90a882e WD |
269 | fnamecmp_type = FNAMECMP_FNAME; |
270 | ||
ffc18846 WD |
271 | if (statret == 0 && !S_ISREG(sx.st.st_mode)) { |
272 | - if (delete_item(fname, sx.st.st_mode, "regular file", del_opts) != 0) | |
7d006b5b | 273 | + if (delete_item(fname, sx.st.st_mode, FF_STAT(sx.st), "regular file", del_opts) != 0) |
ffc18846 | 274 | goto cleanup; |
f90a882e WD |
275 | statret = -1; |
276 | stat_errno = ENOENT; | |
31611b92 WD |
277 | --- old/options.c |
278 | +++ new/options.c | |
5795bf59 | 279 | @@ -49,6 +49,7 @@ int preserve_hard_links = 0; |
ffc18846 | 280 | int preserve_acls = 0; |
5795bf59 | 281 | int preserve_xattrs = 0; |
31611b92 | 282 | int preserve_perms = 0; |
5e3c6c93 | 283 | +int preserve_fileflags = 0; |
31611b92 WD |
284 | int preserve_executability = 0; |
285 | int preserve_devices = 0; | |
286 | int preserve_specials = 0; | |
58b399b9 | 287 | @@ -212,6 +213,7 @@ static void print_rsync_version(enum log |
31611b92 | 288 | char const *links = "no "; |
58b399b9 | 289 | char const *iconv = "no "; |
31611b92 | 290 | char const *ipv6 = "no "; |
5e3c6c93 | 291 | + char const *fileflags = "no "; |
31611b92 WD |
292 | STRUCT_STAT *dumstat; |
293 | ||
ac2da598 | 294 | #if SUBPROTOCOL_VERSION != 0 |
58b399b9 WD |
295 | @@ -241,6 +243,9 @@ static void print_rsync_version(enum log |
296 | #ifdef ICONV_OPTION | |
297 | iconv = ""; | |
31611b92 | 298 | #endif |
31611b92 | 299 | +#ifdef SUPPORT_FLAGS |
5e3c6c93 | 300 | + fileflags = ""; |
31611b92 | 301 | +#endif |
ac2da598 WD |
302 | |
303 | rprintf(f, "%s version %s protocol version %d%s\n", | |
304 | RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION, subprotocol); | |
58b399b9 | 305 | @@ -254,8 +259,8 @@ static void print_rsync_version(enum log |
5e3c6c93 WD |
306 | (int)(sizeof (int64) * 8)); |
307 | rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n", | |
308 | got_socketpair, hardlinks, links, ipv6, have_inplace); | |
58b399b9 WD |
309 | - rprintf(f, " %sappend, %sACLs, %sxattrs, %siconv\n", |
310 | - have_inplace, acls, xattrs, iconv); | |
311 | + rprintf(f, " %sappend, %sACLs, %sxattrs, %siconv, %sfile-flags\n", | |
312 | + have_inplace, acls, xattrs, iconv, fileflags); | |
5e3c6c93 | 313 | |
31611b92 | 314 | #ifdef MAINTAINER_MODE |
5e3c6c93 | 315 | rprintf(f, "Panic Action: \"%s\"\n", get_panic_action()); |
58b399b9 | 316 | @@ -321,6 +326,7 @@ void usage(enum logcode F) |
31611b92 WD |
317 | rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n"); |
318 | rprintf(F," -H, --hard-links preserve hard links\n"); | |
319 | rprintf(F," -p, --perms preserve permissions\n"); | |
5e3c6c93 | 320 | + rprintf(F," --fileflags preserve file-flags\n"); |
31611b92 | 321 | rprintf(F," -E, --executability preserve the file's executability\n"); |
063cf77b | 322 | rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n"); |
ffc18846 | 323 | #ifdef SUPPORT_ACLS |
58b399b9 | 324 | @@ -458,6 +464,8 @@ static struct poptOption long_options[] |
31611b92 WD |
325 | {"perms", 'p', POPT_ARG_VAL, &preserve_perms, 1, 0, 0 }, |
326 | {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, | |
327 | {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, | |
5e3c6c93 WD |
328 | + {"fileflags", 0, POPT_ARG_VAL, &preserve_fileflags, 1, 0, 0 }, |
329 | + {"no-fileflags", 0, POPT_ARG_VAL, &preserve_fileflags, 0, 0, 0 }, | |
31611b92 | 330 | {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 }, |
ffc18846 WD |
331 | {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 }, |
332 | {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
58b399b9 | 333 | @@ -1236,6 +1244,15 @@ int parse_arguments(int *argc, const cha |
31611b92 WD |
334 | } |
335 | #endif | |
336 | ||
337 | +#ifndef SUPPORT_FLAGS | |
5e3c6c93 | 338 | + if (preserve_fileflags) { |
31611b92 WD |
339 | + snprintf(err_buf, sizeof err_buf, |
340 | + "file flags are not supported on this %s\n", | |
341 | + am_server ? "server" : "client"); | |
342 | + return 0; | |
343 | + } | |
344 | +#endif | |
345 | + | |
346 | if (write_batch && read_batch) { | |
347 | snprintf(err_buf, sizeof err_buf, | |
348 | "--write-batch and --read-batch can not be used together\n"); | |
58b399b9 | 349 | @@ -1712,6 +1729,9 @@ void server_options(char **args,int *arg |
31611b92 WD |
350 | if (xfer_dirs && !recurse && delete_mode && am_sender) |
351 | args[ac++] = "--no-r"; | |
352 | ||
5e3c6c93 | 353 | + if (preserve_fileflags) |
31611b92 WD |
354 | + args[ac++] = "--flags"; |
355 | + | |
356 | if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) { | |
357 | if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0) | |
358 | goto oom; | |
359 | --- old/rsync.c | |
360 | +++ new/rsync.c | |
58b399b9 | 361 | @@ -31,6 +31,7 @@ extern int dry_run; |
ffc18846 | 362 | extern int preserve_acls; |
5795bf59 | 363 | extern int preserve_xattrs; |
31611b92 | 364 | extern int preserve_perms; |
5e3c6c93 | 365 | +extern int preserve_fileflags; |
31611b92 WD |
366 | extern int preserve_executability; |
367 | extern int preserve_times; | |
368 | extern int omit_dir_times; | |
58b399b9 WD |
369 | @@ -61,6 +62,16 @@ iconv_t ic_send = (iconv_t)-1, ic_recv = |
370 | int ic_ndx; | |
371 | #endif | |
ffc18846 | 372 | |
9fa103b8 WD |
373 | +#ifdef SUPPORT_FLAGS |
374 | +#ifndef UF_NOUNLINK | |
375 | +#define UF_NOUNLINK 0 | |
376 | +#endif | |
377 | +#ifndef SF_NOUNLINK | |
378 | +#define SF_NOUNLINK 0 | |
379 | +#endif | |
ffc18846 | 380 | +#define NOCHANGE_FLAGS (UF_IMMUTABLE|UF_APPEND|UF_NOUNLINK|SF_IMMUTABLE|SF_APPEND|SF_NOUNLINK) |
9fa103b8 | 381 | +#endif |
ffc18846 | 382 | + |
58b399b9 WD |
383 | static const char *default_charset(void) |
384 | { | |
385 | #if defined HAVE_LIBCHARSET_H && defined HAVE_LOCALE_CHARSET | |
386 | @@ -265,6 +276,41 @@ mode_t dest_mode(mode_t flist_mode, mode | |
f90a882e WD |
387 | return new_mode; |
388 | } | |
389 | ||
390 | +#ifdef SUPPORT_FLAGS | |
391 | +/* Set a file's st_flags. */ | |
392 | +static int set_fileflags(const char *fname, uint32 fileflags) | |
393 | +{ | |
394 | + if (do_chflags(fname, fileflags) != 0) { | |
395 | + rsyserr(FERROR, errno, | |
396 | + "failed to set file flags on %s", | |
397 | + full_fname(fname)); | |
398 | + return 0; | |
399 | + } | |
400 | + | |
401 | + return 1; | |
402 | +} | |
403 | + | |
404 | +/* Remove immutable flags from an object, so it can be altered/removed. */ | |
405 | +void make_mutable(char *fname, mode_t mode, uint32 fileflags) | |
406 | +{ | |
5e3c6c93 | 407 | + if (!preserve_fileflags && S_ISLNK(mode)) |
f90a882e WD |
408 | + return; |
409 | + | |
410 | + if (fileflags & NOCHANGE_FLAGS) | |
411 | + set_fileflags(fname, fileflags & ~NOCHANGE_FLAGS); | |
412 | +} | |
413 | + | |
414 | +/* Undo a prior make_mutable() call. */ | |
415 | +void undo_make_mutable(char *fname, mode_t mode, uint32 fileflags) | |
416 | +{ | |
5e3c6c93 | 417 | + if (!preserve_fileflags && S_ISLNK(mode)) |
f90a882e WD |
418 | + return; |
419 | + | |
420 | + if (fileflags & NOCHANGE_FLAGS) | |
421 | + set_fileflags(fname, fileflags); | |
422 | +} | |
423 | +#endif | |
424 | + | |
5795bf59 WD |
425 | int set_file_attrs(const char *fname, struct file_struct *file, statx *sxp, |
426 | const char *fnamecmp, int flags) | |
f90a882e | 427 | { |
58b399b9 | 428 | @@ -395,6 +441,15 @@ int set_file_attrs(const char *fname, st |
31611b92 WD |
429 | } |
430 | #endif | |
431 | ||
432 | +#ifdef SUPPORT_FLAGS | |
7d006b5b WD |
433 | + if (preserve_fileflags && !S_ISLNK(sxp->st.st_mode) |
434 | + && sxp->st.st_flags != F_FFLAGS(file)) { | |
435 | + if (!set_fileflags(fname, F_FFLAGS(file))) | |
31611b92 | 436 | + return 0; |
31611b92 WD |
437 | + updated = 1; |
438 | + } | |
439 | +#endif | |
440 | + | |
441 | if (verbose > 1 && flags & ATTRS_REPORT) { | |
ff318e90 WD |
442 | if (updated) |
443 | rprintf(FCLIENT, "%s\n", fname); | |
58b399b9 | 444 | @@ -454,6 +509,9 @@ void finish_transfer(const char *fname, |
5795bf59 | 445 | set_file_attrs(fnametmp, file, NULL, fnamecmp, |
f90a882e | 446 | ok_to_set_time ? 0 : ATTRS_SKIP_MTIME); |
31611b92 WD |
447 | |
448 | +#ifdef SUPPORT_FLAGS | |
7d006b5b | 449 | + make_mutable(fnametmp, file->mode, F_FFLAGS(file)); |
31611b92 | 450 | +#endif |
f90a882e WD |
451 | /* move tmp file over real file */ |
452 | if (verbose > 2) | |
453 | rprintf(FINFO, "renaming %s to %s\n", fnametmp, fname); | |
58b399b9 | 454 | @@ -468,6 +526,9 @@ void finish_transfer(const char *fname, |
f90a882e WD |
455 | } |
456 | if (ret == 0) { | |
457 | /* The file was moved into place (not copied), so it's done. */ | |
31611b92 | 458 | +#ifdef SUPPORT_FLAGS |
7d006b5b | 459 | + undo_make_mutable(fname, file->mode, F_FFLAGS(file)); |
31611b92 | 460 | +#endif |
f90a882e WD |
461 | return; |
462 | } | |
463 | /* The file was copied, so tweak the perms of the copied file. If it | |
31611b92 WD |
464 | --- old/rsync.h |
465 | +++ new/rsync.h | |
ffc18846 | 466 | @@ -56,6 +56,7 @@ |
caf38d8d WD |
467 | #define XMIT_RDEV_MINOR_8_pre30 (1<<11) /* protocols 28 - 29 */ |
468 | #define XMIT_GROUP_NAME_FOLLOWS (1<<11) /* protocols 30 - NOW */ | |
469 | #define XMIT_HLINK_FIRST (1<<12) /* protocols 30 - NOW */ | |
470 | +#define XMIT_SAME_FLAGS (1<<14) /* protocols ?? - NOW */ | |
31611b92 WD |
471 | |
472 | /* These flags are used in the live flist data. */ | |
473 | ||
58b399b9 | 474 | @@ -403,6 +404,10 @@ enum msgcode { |
7e27b6c0 | 475 | #endif |
6e6f514c WD |
476 | #endif |
477 | ||
478 | +#ifdef HAVE_CHFLAGS | |
479 | +#define SUPPORT_FLAGS 1 | |
480 | +#endif | |
481 | + | |
482 | /* Find a variable that is either exactly 32-bits or longer. | |
483 | * If some code depends on 32-bit truncation, it will need to | |
484 | * take special action in a "#if SIZEOF_INT32 > 4" section. */ | |
58b399b9 | 485 | @@ -582,6 +587,7 @@ struct file_struct { |
7e27b6c0 | 486 | extern int file_extra_cnt; |
fdf967c7 WD |
487 | extern int preserve_uid; |
488 | extern int preserve_gid; | |
489 | +extern int preserve_fileflags; | |
ffc18846 | 490 | extern int preserve_acls; |
5795bf59 | 491 | extern int preserve_xattrs; |
fdf967c7 | 492 | |
58b399b9 | 493 | @@ -616,6 +622,7 @@ extern int preserve_xattrs; |
1aa236e1 | 494 | /* When the associated option is on, all entries will have these present: */ |
fc068916 WD |
495 | #define F_OWNER(f) REQ_EXTRA(f, preserve_uid)->unum |
496 | #define F_GROUP(f) REQ_EXTRA(f, preserve_gid)->unum | |
7d006b5b | 497 | +#define F_FFLAGS(f) REQ_EXTRA(f, preserve_fileflags)->unum |
5795bf59 WD |
498 | #define F_ACL(f) REQ_EXTRA(f, preserve_acls)->num |
499 | #define F_XATTR(f) REQ_EXTRA(f, preserve_xattrs)->num | |
58b399b9 | 500 | #define F_NDX(f) REQ_EXTRA(f, ic_ndx)->num |
31611b92 WD |
501 | --- old/rsync.yo |
502 | +++ new/rsync.yo | |
03019e41 | 503 | @@ -321,6 +321,7 @@ to the detailed description below for a |
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 |
31611b92 | 507 | + --flags 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) |
58b399b9 | 511 | @@ -520,7 +521,9 @@ specified, in which case bf(-r) is not i |
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). | |
516 | +specify bf(-H). Note also that for compatibility, bf(-a) | |
517 | +currently bf(does not include --flags) (see there) to include preserving | |
518 | +change file flags (if supported by the OS). | |
519 | ||
520 | dit(--no-OPTION) You may turn off one or more implied options by prefixing | |
521 | the option name with "no-". Not all options may be prefixed with a "no-": | |
58b399b9 | 522 | @@ -845,6 +848,13 @@ extended attributes to be the same as th |
5795bf59 WD |
523 | only if the remote machine's rsync supports this option also. This is |
524 | a non-standard option. | |
31611b92 WD |
525 | |
526 | +dit(bf(--flags)) This option causes rsync to update the change file flags | |
f90a882e | 527 | +to be the same as the source file, if your OS supports the bf(chflags)(2) |
31611b92 WD |
528 | +system call. In any case, an attempt is made to remove flags that would |
529 | +prevent a file to be altered. Some flags can only be altered by the | |
530 | +super-user and can only be unset below a certain secure-level (usually | |
531 | +single-user mode). | |
532 | + | |
533 | dit(bf(--chmod)) This option tells rsync to apply one or more | |
534 | comma-separated "chmod" strings to the permission of the files in the | |
535 | transfer. The resulting value is treated as though it was the permissions | |
536 | --- old/syscall.c | |
537 | +++ new/syscall.c | |
58b399b9 | 538 | @@ -162,6 +162,15 @@ int do_chmod(const char *path, mode_t mo |
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; |