1 --- coreutils-6.2.orig/configure.ac
2 +++ coreutils-6.2/configure.ac
3 @@ -246,6 +246,9 @@ AC_CHECK_DECLS([strtoimax, strtoumax])
7 +# Extended attribute copying.
10 AM_GNU_GETTEXT([external], [need-formatstring-macros])
11 AM_GNU_GETTEXT_VERSION([0.15])
14 +++ coreutils-6.2/m4/xattr.m4
16 +# xattr.m4 - check for Extended Attributes (Linux)
18 +# Copyright (C) 2003 Free Software Foundation, Inc.
20 +# This program is free software; you can redistribute it and/or modify
21 +# it under the terms of the GNU General Public License as published by
22 +# the Free Software Foundation; either version 2, or (at your option)
25 +# This program is distributed in the hope that it will be useful,
26 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
27 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 +# GNU General Public License for more details.
30 +# You should have received a copy of the GNU General Public License
31 +# along with this program; if not, write to the Free Software Foundation,
32 +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
34 +# Written by Andreas Gruenbacher.
36 +AC_DEFUN([AC_FUNC_XATTR],
38 + AC_CHECK_HEADERS(attr/error_context.h attr/libattr.h)
39 + if test "$ac_cv_header_attr_libattr_h" = yes \
40 + && test "$ac_cv_header_attr_error_context_h" = yes; then
45 + AC_DEFINE_UNQUOTED(USE_XATTR, $use_xattr,
46 + [Define if you want extended attribute support.])
47 + xattr_saved_LIBS=$LIBS
48 + AC_SEARCH_LIBS(attr_copy_file, attr,
49 + [test "$ac_cv_search_attr_copy_file" = "none required" || LIB_XATTR=$ac_cv_search_attr_copy_file])
51 + AC_CHECK_FUNCS(attr_copy_file)
52 + LIBS=$xattr_saved_LIBS
54 --- coreutils-6.2.orig/src/Makefile.am
55 +++ coreutils-6.2/src/Makefile.am
56 @@ -112,6 +112,10 @@ cp_LDADD += $(LIB_ACL)
57 mv_LDADD += $(LIB_ACL)
58 ginstall_LDADD += $(LIB_ACL)
60 +cp_LDADD += $(LIB_XATTR)
61 +mv_LDADD += $(LIB_XATTR)
62 +ginstall_LDADD += $(LIB_XATTR)
64 $(PROGRAMS): ../lib/libcoreutils.a
67 --- coreutils-6.2.orig/src/copy.c
68 +++ coreutils-6.2/src/copy.c
70 #include "xreadlink.h"
75 +# include <attr/error_context.h>
76 +# include <attr/libattr.h>
80 # define HAVE_FCHOWN false
81 # define fchown(fd, uid, gid) (-1)
82 @@ -118,6 +124,98 @@ is_ancestor (const struct stat *sb, cons
88 +copy_xattr_error (struct error_context *ctx, const char *fmt, ...)
95 + /* There is no error function that takes a va_list argument,
96 + so we print the message in a buffer first. */
99 + len = vsnprintf (NULL, 0, fmt, ap);
103 + buffer = xmalloc (len + 1);
104 + va_start (ap, fmt);
105 + vsnprintf (buffer, len + 1, fmt, ap);
107 + error (0, err, "%s", buffer);
113 +copy_xattr_quote (struct error_context *ctx, const char *str)
115 + return xstrdup (quote (str));
119 +copy_xattr_free (struct error_context *ctx, const char *str)
121 + free ((void *) str);
124 +struct copy_xattr_context {
125 + struct error_context ctx;
126 + struct cp_options *x;
130 +copy_xattr_filter (const char *name, struct error_context *ctx)
132 + struct copy_xattr_context *copy_ctx = (struct copy_xattr_context *) ctx;
135 + /* We handle POSIX ACLs separately. */
136 + if (!strcmp(name, "system.posix_acl_access")
137 + || !strcmp(name, "system.posix_acl_default"))
140 + action = attr_copy_action(name, ctx);
141 + return (action != ATTR_ACTION_SKIP &&
142 + (!copy_ctx->x->preserve_mode
143 + || action != ATTR_ACTION_PERMISSIONS));
145 +#endif /* USE_XATTR */
148 +copy_xattrs (const char *src_path, int source_desc, const char *dst_path,
149 + int dest_desc, const struct cp_options *x)
151 + struct copy_xattr_context copy_xattr_ctx = {
152 + { copy_xattr_error,
159 + if (x->preserve_xattrs)
163 + if (source_desc != -1 && dest_desc != -1)
164 + ret = attr_copy_fd(src_path, source_desc, dst_path, dest_desc,
165 + copy_xattr_filter, ©_xattr_ctx.ctx);
167 + ret = attr_copy_file (src_path, dst_path,
168 + copy_xattr_filter, ©_xattr_ctx.ctx);
169 + return ret == 0 || !x->require_preserve;
173 +#else /* USE_XATTR */
175 +#endif /* USE_XATTR */
178 /* Read the contents of the directory SRC_NAME_IN, and recursively
179 copy the contents to DST_NAME_IN. NEW_DST is true if
180 DST_NAME_IN is a directory that was created previously in the
181 @@ -509,6 +607,9 @@ copy_reg (char const *src_name, char con
185 + if (!copy_xattrs (src_name, source_desc, dst_name, dest_desc, x))
186 + return_val = false;
188 set_author (dst_name, dest_desc, src_sb);
190 if (x->preserve_mode || x->move_mode)
191 @@ -1755,6 +1856,9 @@ copy_internal (char const *src_name, cha
195 + if (!copy_xattrs (src_name, -1, dst_name, -1, x))
196 + delayed_ok = false;
198 set_author (dst_name, -1, &src_sb);
200 if (x->preserve_mode || x->move_mode)
201 --- coreutils-6.2.orig/src/copy.h
202 +++ coreutils-6.2/src/copy.h
203 @@ -128,6 +128,9 @@ struct cp_options
205 bool preserve_timestamps;
207 + /* If true, attempt to copy extended attributes. */
208 + bool preserve_xattrs;
210 /* Enabled for mv, and for cp by the --preserve=links option.
211 If true, attempt to preserve in the destination files any
212 logical hard links between the source files. If used with cp's
213 --- coreutils-6.2.orig/src/cp.c
214 +++ coreutils-6.2/src/cp.c
215 @@ -191,7 +191,7 @@ Mandatory arguments to long options are
216 -p same as --preserve=mode,ownership,timestamps\n\
217 --preserve[=ATTR_LIST] preserve the specified attributes (default:\n\
218 mode,ownership,timestamps), if possible\n\
219 - additional attributes: links, all\n\
220 + additional attributes: links, xattrs, all\n\
223 --no-preserve=ATTR_LIST don't preserve the specified attributes\n\
224 @@ -724,6 +724,7 @@ cp_option_init (struct cp_options *x)
225 x->preserve_links = false;
226 x->preserve_mode = false;
227 x->preserve_timestamps = false;
228 + x->preserve_xattrs = false;
230 x->require_preserve = false;
231 x->recursive = false;
232 @@ -752,18 +753,21 @@ decode_preserve_arg (char const *arg, st
239 static enum File_attribute const preserve_vals[] =
241 PRESERVE_MODE, PRESERVE_TIMESTAMPS,
242 - PRESERVE_OWNERSHIP, PRESERVE_LINK, PRESERVE_ALL
243 + PRESERVE_OWNERSHIP, PRESERVE_LINK,
244 + PRESERVE_XATTRS, PRESERVE_ALL
246 /* Valid arguments to the `--preserve' option. */
247 static char const* const preserve_args[] =
249 "mode", "timestamps",
250 - "ownership", "links", "all", NULL
251 + "ownership", "links",
252 + "xattrs", "all", NULL
254 ARGMATCH_VERIFY (preserve_args, preserve_vals);
256 @@ -799,11 +803,16 @@ decode_preserve_arg (char const *arg, st
257 x->preserve_links = on_off;
260 + case PRESERVE_XATTRS:
261 + x->preserve_xattrs = on_off;
265 x->preserve_mode = on_off;
266 x->preserve_timestamps = on_off;
267 x->preserve_ownership = on_off;
268 x->preserve_links = on_off;
269 + x->preserve_xattrs = on_off;
273 --- coreutils-6.2.orig/src/install.c
274 +++ coreutils-6.2/src/install.c
275 @@ -154,6 +154,7 @@ cp_option_init (struct cp_options *x)
276 x->preserve_links = false;
277 x->preserve_mode = false;
278 x->preserve_timestamps = false;
279 + x->preserve_xattrs = false;
280 x->require_preserve = false;
281 x->recursive = false;
282 x->sparse_mode = SPARSE_AUTO;
283 --- coreutils-6.2.orig/src/mv.c
284 +++ coreutils-6.2/src/mv.c
285 @@ -125,6 +125,7 @@ cp_option_init (struct cp_options *x)
286 x->preserve_links = true;
287 x->preserve_mode = true;
288 x->preserve_timestamps = true;
289 + x->preserve_xattrs = true;
290 x->require_preserve = false; /* FIXME: maybe make this an option */
292 x->sparse_mode = SPARSE_AUTO; /* FIXME: maybe make this an option */
293 --- coreutils-6.2.orig/doc/coreutils.texi
294 +++ coreutils-6.2/doc/coreutils.texi
295 @@ -6948,6 +6948,8 @@ Preserve in the destination files
296 any links between corresponding source files.
297 @c Give examples illustrating how hard links are preserved.
298 @c Also, show how soft links map to hard links with -L and -H.
300 +Preserve extended attributes. (See /etc/xattr.conf.)
302 Preserve all file attributes.
303 Equivalent to specifying all of the above.