2 # Ensure that cp --preserve=xattr, cp --preserve=all and mv preserve extended
3 # attributes and install does not preserve extended attributes.
4 # cp -a should preserve xattr, error diagnostics should not be displayed
6 # Copyright (C) 2009 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 if test "$VERBOSE" = yes; then
30 # Skip this test if cp was built without xattr support:
31 touch src dest || framework_failure
32 cp --preserve=xattr -n src dest 2>/dev/null \
33 || skip_test_ "coreutils built without xattr support"
35 # this code was taken from test mv/backup-is-src
36 cleanup_() { rm -rf "$other_partition_tmpdir"; }
37 . "$abs_srcdir/other-fs-tmpdir"
38 b_other="$other_partition_tmpdir/b"
39 rm -f $b_other || framework_failure
41 # testing xattr name-value pair
44 xattr_pair="$xattr_name=\"$xattr_value\""
46 # create new file and check its xattrs
47 touch a || framework_failure
48 getfattr -d a >out_a || skip_test_ "failed to get xattr of file"
49 grep -F "$xattr_pair" out_a >/dev/null && framework_failure
51 # try to set user xattr on file
52 setfattr -n "$xattr_name" -v "$xattr_value" a >out_a \
53 || skip_test_ "failed to set xattr of file"
54 getfattr -d a >out_a || skip_test_ "failed to get xattr of file"
55 grep -F "$xattr_pair" out_a >/dev/null \
56 || skip_test_ "failed to set xattr of file"
60 # cp should not preserve xattr by default
62 getfattr -d b >out_b || skip_test_ "failed to get xattr of file"
63 grep -F "$xattr_pair" out_b >/dev/null && fail=1
65 # test if --preserve=xattr option works
66 cp --preserve=xattr a b || fail=1
67 getfattr -d b >out_b || skip_test_ "failed to get xattr of file"
68 grep -F "$xattr_pair" out_b >/dev/null || fail=1
70 #test if --preserve=all option works
71 cp --preserve=all a c || fail=1
72 getfattr -d c >out_c || skip_test_ "failed to get xattr of file"
73 grep -F "$xattr_pair" out_c >/dev/null || fail=1
75 #test if -a option works without any diagnostics
76 cp -a a d 2>err && test -s err && fail=1
77 getfattr -d d >out_d || skip_test_ "failed to get xattr of file"
78 grep -F "$xattr_pair" out_d >/dev/null || fail=1
80 rm b || framework_failure
82 # install should never preserve xattr
83 ginstall a b || fail=1
84 getfattr -d b >out_b || skip_test_ "failed to get xattr of file"
85 grep -F "$xattr_pair" out_b >/dev/null && fail=1
87 # mv should preserve xattr when renaming within a file system.
88 # This is implicitly done by rename () and doesn't need explicit
89 # xattr support in mv.
91 getfattr -d b >out_b || skip_test_ "failed to get xattr of file"
92 grep -F "$xattr_pair" out_b >/dev/null || cat >&2 <<EOF
93 =================================================================
95 rename () does not preserve extended attributes
96 =================================================================
99 # try to set user xattr on file on other partition
101 touch $b_other || framework_failure
102 setfattr -n "$xattr_name" -v "$xattr_value" $b_other >out_a 2>/dev/null \
104 getfattr -d $b_other >out_b 2>/dev/null || test_mv=0
105 grep -F "$xattr_pair" out_b >/dev/null || test_mv=0
106 rm -f $b_other || framework_failure
108 if test $test_mv -eq 1; then
109 # mv should preserve xattr when copying content from one partition to another
110 mv b $b_other || fail=1
111 getfattr -d $b_other >out_b 2>/dev/null || skip_test_ "failed to get xattr of file"
112 grep -F "$xattr_pair" out_b >/dev/null || fail=1
115 =================================================================
117 failed to set xattr of file $b_other
118 =================================================================