summaryrefslogtreecommitdiff
path: root/tests/misc
diff options
context:
space:
mode:
authorKamil Dudka <kdudka@redhat.com>2009-01-23 12:17:53 +0100
committerJim Meyering <meyering@redhat.com>2009-01-29 13:26:07 +0100
commit0889381cbfdbb4895e6b8693d14c0f5c77bc85bc (patch)
tree1c93168a0d0c7e5ff72df37c4b34607b0eb3aaea /tests/misc
parent1bdf77ad523fca6f3781f5614706246f20394a62 (diff)
downloadcoreutils-0889381cbfdbb4895e6b8693d14c0f5c77bc85bc.tar.xz
cp/mv: add xattr support
This patch was originally written by Andreas Grünbacher, nowadays available at http://www.suse.de/~agruen/coreutils/5.91/coreutils-xattr.diff * bootstrap.conf: Add gnulib module verror. * po/POTFILES.in: Add lib/verror.c. * m4/xattr.m4: Check for libattr availability, new configure option --disable-xattr. * m4/prereq.m4: Require gl_FUNC_XATTR. * src/Makefile.am: Link cp, mv and ginstall with libattr. * src/copy.h: Add preserve_xattr and require_preserve_xattr to cp_options. * src/copy.c (copy_attr_error): New function to handle errors during xattr copying. (copy_attr_quote): New function to quote file name in error messages printed by libattr. (copy_attr_free): Empty function requested by libattr to free quoted string. (copy_attr_by_fd): New fd-oriented function to copy xattr. (copy_attr_by_name): New name-oriented function to copy xattr. (copy_reg, copy_internal): Call copy_extended_attributes function. * src/cp.c (usage): Mention new --preserve=xattr option. (decode_preserve_arg): Handle new --preserve=xattr option. * src/mv.c: Always attempt to preserve xattr. * src/install.c: Never attempt to preserve xattr. * tests/misc/xattr: New test for xattr support in cp, mv and install. * tests/Makefile.am: Add the new test to list. * doc/coreutils.texi: Mention xattr support, new --preserve=xattr option. * NEWS: Mention the change.
Diffstat (limited to 'tests/misc')
-rwxr-xr-xtests/misc/xattr111
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/misc/xattr b/tests/misc/xattr
new file mode 100755
index 000000000..4137c53cb
--- /dev/null
+++ b/tests/misc/xattr
@@ -0,0 +1,111 @@
+#!/bin/sh
+# Ensure that cp --preserve=xattr and mv preserve extended attributes and
+# install does not preserve extended attributes.
+
+# Copyright (C) 2009 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+if test "$VERBOSE" = yes; then
+ set -x
+ cp --version
+ mv --version
+ ginstall --version
+fi
+
+. $srcdir/test-lib.sh
+
+# Skip this test if cp was built without xattr support:
+touch src dest || framework_failure
+cp --preserve=xattr -n src dest 2>/dev/null \
+ || skip_test_ "coreutils built without xattr support"
+
+# this code was taken from test mv/backup-is-src
+cleanup_() { rm -rf "$other_partition_tmpdir"; }
+. "$abs_srcdir/other-fs-tmpdir"
+b_other="$other_partition_tmpdir/b"
+rm -f $b_other || framework_failure
+
+# testing xattr name-value pair
+xattr_name="user.foo"
+xattr_value="bar"
+xattr_pair="$xattr_name=\"$xattr_value\""
+
+# create new file and check its xattrs
+touch a || framework_failure
+getfattr -d a >out_a || skip_test_ "failed to get xattr of file"
+grep -F "$xattr_pair" out_a >/dev/null && framework_failure
+
+# try to set user xattr on file
+setfattr -n "$xattr_name" -v "$xattr_value" a >out_a \
+ || skip_test_ "failed to set xattr of file"
+getfattr -d a >out_a || skip_test_ "failed to get xattr of file"
+grep -F "$xattr_pair" out_a >/dev/null \
+ || skip_test_ "failed to set xattr of file"
+
+fail=0
+
+# cp should not preserve xattr by default
+cp a b || fail=1
+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=xattr option works
+cp --preserve=xattr a b || fail=1
+getfattr -d b >out_b || skip_test_ "failed to get xattr of file"
+grep -F "$xattr_pair" out_b >/dev/null || fail=1
+
+rm b || framework_failure
+
+# install should never preserve xattr
+ginstall a b || fail=1
+getfattr -d b >out_b || skip_test_ "failed to get xattr of file"
+grep -F "$xattr_pair" out_b >/dev/null && fail=1
+
+# mv should preserve xattr when renaming within a file system.
+# This is implicitly done by rename () and doesn't need explicit
+# xattr support in mv.
+mv a b || fail=1
+getfattr -d b >out_b || skip_test_ "failed to get xattr of file"
+grep -F "$xattr_pair" out_b >/dev/null || cat >&2 <<EOF
+=================================================================
+$0: WARNING!!!
+rename () does not preserve extended attributes
+=================================================================
+EOF
+
+# try to set user xattr on file on other partition
+test_mv=1
+touch $b_other || framework_failure
+setfattr -n "$xattr_name" -v "$xattr_value" $b_other >out_a 2>/dev/null \
+ || test_mv=0
+getfattr -d $b_other >out_b 2>/dev/null || test_mv=0
+grep -F "$xattr_pair" out_b >/dev/null || test_mv=0
+rm -f $b_other || framework_failure
+
+if test $test_mv -eq 1; then
+ # mv should preserve xattr when copying content from one partition to another
+ mv b $b_other || fail=1
+ getfattr -d $b_other >out_b 2>/dev/null || skip_test_ "failed to get xattr of file"
+ grep -F "$xattr_pair" out_b >/dev/null || fail=1
+else
+ cat >&2 <<EOF
+=================================================================
+$0: WARNING!!!
+failed to set xattr of file $b_other
+=================================================================
+EOF
+fi
+
+Exit $fail