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-2012 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 .
"${srcdir=.}/init.sh"; path_prepend_ ..
/src
22 print_ver_
cp mv ginstall
24 # Skip this test if cp was built without xattr support:
25 touch src dest || framework_failure_
26 cp --preserve=xattr
-n src dest \
27 || skip_
"coreutils built without xattr support"
29 # this code was taken from test mv/backup-is-src
30 cleanup_
() { rm -rf "$other_partition_tmpdir"; }
31 .
"$abs_srcdir/other-fs-tmpdir"
32 b_other
="$other_partition_tmpdir/b"
33 rm -f "$b_other" || framework_failure_
35 # testing xattr name-value pair
38 xattr_pair
="$xattr_name=\"$xattr_value\""
40 # create new file and check its xattrs
41 touch a || framework_failure_
42 getfattr
-d a
>out_a || skip_
"failed to get xattr of file"
43 grep -F "$xattr_pair" out_a
&& framework_failure_
45 # try to set user xattr on file
46 setfattr
-n "$xattr_name" -v "$xattr_value" a
>out_a \
47 || skip_
"failed to set xattr of file"
48 getfattr
-d a
>out_a || skip_
"failed to get xattr of file"
49 grep -F "$xattr_pair" out_a \
50 || skip_
"failed to set xattr of file"
53 # cp should not preserve xattr by default
55 getfattr
-d b
>out_b || skip_
"failed to get xattr of file"
56 grep -F "$xattr_pair" out_b
&& fail
=1
58 # test if --preserve=xattr option works
59 cp --preserve=xattr a b || fail
=1
60 getfattr
-d b
>out_b || skip_
"failed to get xattr of file"
61 grep -F "$xattr_pair" out_b || fail
=1
63 # test if --preserve=all option works
64 cp --preserve=all a c || fail
=1
65 getfattr
-d c
>out_c || skip_
"failed to get xattr of file"
66 grep -F "$xattr_pair" out_c || fail
=1
68 # cp's -a option must produce no diagnostics.
69 cp -a a d
2>err
&& test -s err
&& fail
=1
70 getfattr
-d d
>out_d || skip_
"failed to get xattr of file"
71 grep -F "$xattr_pair" out_d || fail
=1
73 # test if --preserve=xattr works even for files without write access
74 chmod a-w a || framework_failure_
76 cp --preserve=xattr a e || fail
=1
77 getfattr
-d e
>out_e || skip_
"failed to get xattr of file"
78 grep -F "$xattr_pair" out_e || fail
=1
80 # Ensure that permission bits are preserved, too.
81 src_perm
=$
(stat
--format=%a a
)
82 dst_perm
=$
(stat
--format=%a e
)
83 test "$dst_perm" = "$src_perm" || fail
=1
85 chmod u
+w a || framework_failure_
87 rm b || framework_failure_
89 # install should never preserve xattr
90 ginstall a b || fail
=1
91 getfattr
-d b
>out_b || skip_
"failed to get xattr of file"
92 grep -F "$xattr_pair" out_b
&& fail
=1
94 # mv should preserve xattr when renaming within a file system.
95 # This is implicitly done by rename () and doesn't need explicit
96 # xattr support in mv.
98 getfattr
-d b
>out_b || skip_
"failed to get xattr of file"
99 grep -F "$xattr_pair" out_b ||
cat >&2 <<EOF
100 =================================================================
102 rename () does not preserve extended attributes
103 =================================================================
106 # try to set user xattr on file on other partition
108 touch "$b_other" || framework_failure_
109 setfattr
-n "$xattr_name" -v "$xattr_value" "$b_other" >out_a \
111 getfattr
-d "$b_other" >out_b || test_mv
=0
112 grep -F "$xattr_pair" out_b || test_mv
=0
113 rm -f "$b_other" || framework_failure_
115 if test $test_mv -eq 1; then
116 # mv should preserve xattr when copying content from one partition to another
117 mv b
"$b_other" || fail
=1
118 getfattr
-d "$b_other" >out_b ||
119 skip_
"failed to get xattr of file"
120 grep -F "$xattr_pair" out_b || fail
=1
123 =================================================================
125 failed to set xattr of file $b_other
126 =================================================================