original files in the copy (but do not attempt to preserve internal
directory structure; i.e., @samp{ls -U} may list the entries in a copied
directory in a different order).
-Try to preserve SELinux security context, but ignore any failure to do that
-and print no corresponding diagnostic.
-This option does not preserve extended attributes(xattr) at the moment.
-Equivalent to @option{-dR --preserve=all} with a few exceptions.
+Try to preserve SELinux security context and extended attributes (xattr),
+but ignore any failure to do that and print no corresponding diagnostic.
+Equivalent to @option{-dR --preserve=all} with the reduced diagnostics.
@item -b
@itemx @w{@kbd{--backup}[=@var{method}]}
static bool
copy_attr_by_fd (char const *src_path, int src_fd,
- char const *dst_path, int dst_fd)
+ char const *dst_path, int dst_fd, const struct cp_options *x)
{
struct error_context ctx =
{
.quote = copy_attr_quote,
.quote_free = copy_attr_free
};
- return 0 == attr_copy_fd (src_path, src_fd, dst_path, dst_fd, 0, &ctx);
+ return 0 == attr_copy_fd (src_path, src_fd, dst_path, dst_fd, 0,
+ x->reduce_diagnostics ? NULL : &ctx);
}
static bool
-copy_attr_by_name (char const *src_path, char const *dst_path)
+copy_attr_by_name (char const *src_path, char const *dst_path,
+ const struct cp_options *x)
{
struct error_context ctx =
{
.quote = copy_attr_quote,
.quote_free = copy_attr_free
};
- return 0 == attr_copy_file (src_path, dst_path, 0, &ctx);
+ return 0 == attr_copy_file (src_path, dst_path, 0,
+ x-> reduce_diagnostics ? NULL :&ctx);
}
#else /* USE_XATTR */
static bool
copy_attr_by_fd (char const *src_path, int src_fd,
- char const *dst_path, int dst_fd)
+ char const *dst_path, int dst_fd, const struct cp_options *x)
{
return true;
}
static bool
-copy_attr_by_name (char const *src_path, char const *dst_path)
+copy_attr_by_name (char const *src_path, char const *dst_path,
+ const struct cp_options *x)
{
return true;
}
set_author (dst_name, dest_desc, src_sb);
if (x->preserve_xattr && ! copy_attr_by_fd (src_name, source_desc,
- dst_name, dest_desc)
+ dst_name, dest_desc, x)
&& x->require_preserve_xattr)
return false;
set_author (dst_name, -1, &src_sb);
- if (x->preserve_xattr && ! copy_attr_by_name (src_name, dst_name)
+ if (x->preserve_xattr && ! copy_attr_by_name (src_name, dst_name, x)
&& x->require_preserve_xattr)
return false;
#!/bin/sh
-# Ensure that cp --preserve=xattr and mv preserve extended attributes and
-# install does not preserve extended attributes.
+# Ensure that cp --preserve=xattr, cp --preserve=all and mv preserve extended
+# attributes and install does not preserve extended attributes.
+# cp -a should preserve xattr, error diagnostics should not be displayed
# Copyright (C) 2009 Free Software Foundation, Inc.
getfattr -d b >out_b || skip_test_ "failed to get xattr of file"
grep -F "$xattr_pair" out_b >/dev/null || fail=1
+#test if --preserve=all option works
+cp --preserve=all a c || fail=1
+getfattr -d c >out_c || skip_test_ "failed to get xattr of file"
+grep -F "$xattr_pair" out_c >/dev/null || fail=1
+
+#test if -a option works without any diagnostics
+cp -a a d 2>err && test -s err && fail=1
+getfattr -d d >out_d || skip_test_ "failed to get xattr of file"
+grep -F "$xattr_pair" out_d >/dev/null || fail=1
+
rm b || framework_failure
# install should never preserve xattr