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