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