1 This patch provides --flags, which preserves the st_flags field.
2 Modified from a patch that was written by Rolf Grossmann:
4 http://www.progtech.net/rsync.flags-patch
8 @@ -527,7 +527,7 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd strd
9 memmove lchown vsnprintf snprintf vasprintf asprintf setsid glob strpbrk \
10 strlcat strlcpy strtol mallinfo getgroups setgroups geteuid getegid \
11 setlocale setmode open64 lseek64 mkstemp64 mtrace va_copy __va_copy \
12 - strerror putenv iconv_open locale_charset nl_langinfo \
13 + chflags strerror putenv iconv_open locale_charset nl_langinfo \
14 sigaction sigprocmask)
16 AC_CHECK_FUNCS(getpgrp tcgetpgrp)
19 @@ -44,6 +44,7 @@ extern int preserve_links;
20 extern int preserve_hard_links;
21 extern int preserve_devices;
22 extern int preserve_specials;
23 +extern int preserve_flags;
24 extern int preserve_uid;
25 extern int preserve_gid;
26 extern int relative_paths;
27 @@ -299,6 +300,9 @@ static void send_file_entry(struct file_
29 static time_t modtime;
32 + static uint32 fileflags;
36 static uint32 rdev_major;
37 @@ -329,6 +333,12 @@ static void send_file_entry(struct file_
38 flags |= XMIT_SAME_MODE;
42 + if (file->fileflags == fileflags)
43 + flags |= XMIT_SAME_FLAGS;
45 + fileflags = file->fileflags;
47 if ((preserve_devices && IS_DEVICE(mode))
48 || (preserve_specials && IS_SPECIAL(mode))) {
49 if (protocol_version < 28) {
50 @@ -412,6 +422,10 @@ static void send_file_entry(struct file_
51 write_int(f, modtime);
52 if (!(flags & XMIT_SAME_MODE))
53 write_int(f, to_wire_mode(mode));
55 + if (preserve_flags && !(flags & XMIT_SAME_FLAGS))
56 + write_int(f, (int)fileflags);
58 if (preserve_uid && !(flags & XMIT_SAME_UID)) {
61 @@ -479,6 +493,9 @@ static struct file_struct *receive_file_
63 static time_t modtime;
66 + static uint32 fileflags;
70 static uint32 rdev_major;
71 @@ -552,9 +569,12 @@ static struct file_struct *receive_file_
72 modtime = (time_t)read_int(f);
73 if (!(flags & XMIT_SAME_MODE))
74 mode = from_wire_mode(read_int(f));
76 if (chmod_modes && !S_ISLNK(mode))
77 mode = tweak_mode(mode, chmod_modes);
79 + if (preserve_flags && !(flags & XMIT_SAME_FLAGS))
80 + fileflags = (uint32)read_int(f);
83 if (preserve_uid && !(flags & XMIT_SAME_UID))
84 uid = (uid_t)read_int(f);
85 @@ -605,6 +625,9 @@ static struct file_struct *receive_file_
86 file->modtime = modtime;
87 file->length = file_length;
90 + file->fileflags = fileflags;
95 @@ -857,6 +880,9 @@ struct file_struct *make_file(char *fnam
96 file->modtime = st.st_mtime;
97 file->length = st.st_size;
98 file->mode = st.st_mode;
100 + file->fileflags = st.st_flags;
102 file->uid = st.st_uid;
103 file->gid = st.st_gid;
107 @@ -123,6 +123,9 @@ static int delete_item(char *fname, int
108 if (!S_ISDIR(mode)) {
109 if (max_delete && ++deletion_count > max_delete)
111 +#ifdef SUPPORT_FLAGS
112 + make_mutable(fname);
114 if (make_backups && (backup_dir || !is_backup_file(fname)))
115 ok = make_backup(fname);
117 @@ -147,10 +150,17 @@ static int delete_item(char *fname, int
120 } else if (make_backups && !backup_dir && !is_backup_file(fname)
121 - && !(flags & DEL_FORCE_RECURSE))
122 + && !(flags & DEL_FORCE_RECURSE)) {
123 +#ifdef SUPPORT_FLAGS
124 + make_mutable(fname);
126 ok = make_backup(fname);
129 +#ifdef SUPPORT_FLAGS
130 + make_mutable(fname);
132 ok = do_rmdir(fname) == 0;
135 if (!(flags & DEL_TERSE))
136 log_delete(fname, mode);
139 @@ -48,6 +48,7 @@ int copy_links = 0;
140 int preserve_links = 0;
141 int preserve_hard_links = 0;
142 int preserve_perms = 0;
143 +int preserve_flags = 0;
144 int preserve_executability = 0;
145 int preserve_devices = 0;
146 int preserve_specials = 0;
147 @@ -200,6 +201,7 @@ static void print_rsync_version(enum log
148 char const *hardlinks = "no ";
149 char const *links = "no ";
150 char const *ipv6 = "no ";
151 + char const *flags = "no ";
152 STRUCT_STAT *dumstat;
154 #ifdef HAVE_SOCKETPAIR
155 @@ -222,6 +224,10 @@ static void print_rsync_version(enum log
159 +#ifdef SUPPORT_FLAGS
163 rprintf(f, "%s version %s protocol version %d\n",
164 RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
165 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
166 @@ -234,9 +240,9 @@ static void print_rsync_version(enum log
167 /* Note that this field may not have type ino_t. It depends
168 * on the complicated interaction between largefile feature
170 - rprintf(f, " %sinplace, %sIPv6, "
171 + rprintf(f, " %sinplace, %sIPv6, %sfile flags, "
172 "%d-bit system inums, %d-bit internal inums\n",
173 - have_inplace, ipv6,
174 + have_inplace, ipv6, flags,
175 (int) (sizeof dumstat->st_ino * 8),
176 (int) (sizeof (int64) * 8));
177 #ifdef MAINTAINER_MODE
178 @@ -302,6 +308,7 @@ void usage(enum logcode F)
179 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
180 rprintf(F," -H, --hard-links preserve hard links\n");
181 rprintf(F," -p, --perms preserve permissions\n");
182 + rprintf(F," --flags preserve file flags\n");
183 rprintf(F," -E, --executability preserve the file's executability\n");
184 rprintf(F," --chmod=CHMOD change the permissions of transferred files\n");
185 rprintf(F," -o, --owner preserve owner (super-user only)\n");
186 @@ -420,6 +427,8 @@ static struct poptOption long_options[]
187 {"perms", 'p', POPT_ARG_VAL, &preserve_perms, 1, 0, 0 },
188 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
189 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
190 + {"flags", 0, POPT_ARG_VAL, &preserve_flags, 1, 0, 0 },
191 + {"no-flags", 0, POPT_ARG_VAL, &preserve_flags, 0, 0, 0 },
192 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
193 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
194 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
195 @@ -1123,6 +1132,15 @@ int parse_arguments(int *argc, const cha
199 +#ifndef SUPPORT_FLAGS
200 + if (preserve_flags) {
201 + snprintf(err_buf, sizeof err_buf,
202 + "file flags are not supported on this %s\n",
203 + am_server ? "server" : "client");
208 if (write_batch && read_batch) {
209 snprintf(err_buf, sizeof err_buf,
210 "--write-batch and --read-batch can not be used together\n");
211 @@ -1580,6 +1598,9 @@ void server_options(char **args,int *arg
212 if (xfer_dirs && !recurse && delete_mode && am_sender)
213 args[ac++] = "--no-r";
215 + if (preserve_flags)
216 + args[ac++] = "--flags";
218 if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) {
219 if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0)
226 extern int preserve_perms;
227 +extern int preserve_flags;
228 extern int preserve_executability;
229 extern int preserve_times;
230 extern int omit_dir_times;
231 @@ -221,6 +222,19 @@ int set_file_attrs(char *fname, struct f
235 +#ifdef SUPPORT_FLAGS
236 + if (preserve_flags && !S_ISLNK(st->st_mode)
237 + && st->st_flags != file->fileflags) {
238 + if (do_chflags(fname, file->fileflags) != 0) {
239 + rsyserr(FERROR, errno,
240 + "failed to set file flags on %s",
241 + full_fname(fname));
248 if (verbose > 1 && flags & ATTRS_REPORT) {
250 rprintf(FCLIENT, "%s\n", fname);
251 @@ -254,6 +268,10 @@ void finish_transfer(char *fname, char *
255 +#ifdef SUPPORT_FLAGS
256 + make_mutable(fname); /* XXX */
261 rprintf(FINFO, "finishing %s\n", fname);
262 @@ -307,3 +325,21 @@ const char *who_am_i(void)
263 return am_server ? "server" : "client";
264 return am_sender ? "sender" : am_generator ? "generator" : "receiver";
267 +#ifdef SUPPORT_FLAGS
268 +/* remove immutable flags from an object, so it can be altered/removed. */
269 +void make_mutable(char *fname)
271 +#define NOCHANGEBITS (UF_IMMUTABLE | UF_APPEND | UF_NOUNLINK | SF_IMMUTABLE | SF_APPEND | SF_NOUNLINK)
277 + /* XXX get rid of this extra stat() */
278 + if (do_lstat(fname, &stb) < 0)
280 + if (stb.st_flags & NOCHANGEBITS)
281 + do_chflags(fname, stb.st_flags & ~NOCHANGEBITS);
287 #define XMIT_HAS_IDEV_DATA (1<<9)
288 #define XMIT_SAME_DEV (1<<10)
289 #define XMIT_RDEV_MINOR_IS_SMALL (1<<11)
290 +#define XMIT_SAME_FLAGS (1<<12)
292 /* These flags are used in the live flist data. */
294 @@ -344,6 +345,10 @@ enum msgcode {
299 +#define SUPPORT_FLAGS 1
302 /* Find a variable that is either exactly 32-bits or longer.
303 * If some code depends on 32-bit truncation, it will need to
304 * take special action in a "#if SIZEOF_INT32 > 4" section. */
305 @@ -526,6 +531,9 @@ struct file_struct {
309 +#ifdef SUPPORT_FLAGS
317 @@ -320,6 +320,7 @@ to the detailed description below for a
318 -K, --keep-dirlinks treat symlinked dir on receiver as dir
319 -H, --hard-links preserve hard links
320 -p, --perms preserve permissions
321 + --flags preserve file flags
322 -E, --executability preserve executability
323 --chmod=CHMOD change the permissions of transferred files
324 -o, --owner preserve owner (super-user only)
325 @@ -503,7 +504,9 @@ specified, in which case bf(-r) is not i
327 Note that bf(-a) bf(does not preserve hardlinks), because
328 finding multiply-linked files is expensive. You must separately
330 +specify bf(-H). Note also that for compatibility, bf(-a)
331 +currently bf(does not include --flags) (see there) to include preserving
332 +change file flags (if supported by the OS).
334 dit(--no-OPTION) You may turn off one or more implied options by prefixing
335 the option name with "no-". Not all options may be prefixed with a "no-":
336 @@ -798,6 +801,13 @@ quote(itemize(
338 If bf(--perms) is enabled, this option is ignored.
340 +dit(bf(--flags)) This option causes rsync to update the change file flags
341 +to be the same as the source file, if your OS supports the chflags(2)
342 +system call. In any case, an attempt is made to remove flags that would
343 +prevent a file to be altered. Some flags can only be altered by the
344 +super-user and can only be unset below a certain secure-level (usually
347 dit(bf(--chmod)) This option tells rsync to apply one or more
348 comma-separated "chmod" strings to the permission of the files in the
349 transfer. The resulting value is treated as though it was the permissions
352 @@ -152,6 +152,15 @@ int do_chmod(const char *path, mode_t mo
356 +#ifdef SUPPORT_FLAGS
357 +int do_chflags(const char *path, u_long flags)
359 + if (dry_run) return 0;
360 + RETURN_ERROR_IF_RO_OR_LO;
361 + return chflags(path, flags);
365 int do_rename(const char *fname1, const char *fname2)
367 if (dry_run) return 0;