tests: adjust PATH to generally include /sbin and /usr/sbin
[coreutils.git] / tests / cp / cp-mv-enotsup-xattr
blob17ac6a4b44d3d381b0a06d580ac6fe9860842b35
1 #!/bin/sh
2 # Ensure that mv, cp -a and cp --preserve=xattr(all) options do work
3 # as expected on file system without their support and do show correct
4 # diagnostics when required
6 # Copyright (C) 2009-2011 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
24 require_root_
26 cwd=`pwd`
27 cleanup_() { cd /; umount "$cwd/noxattr"; umount "$cwd/xattr"; }
29 skip=0
31 # Mount an ext2 loopback file system at $WHERE with $OPTS
32 make_fs() {
33 where="$1"
34 opts="$2"
36 fs="$where.bin"
38 dd if=/dev/zero of="$fs" bs=8192 count=200 > /dev/null 2>&1 \
39 || skip=1
40 mkdir "$where" || skip=1
41 mkfs -t ext2 -F "$fs" ||
42 skip_ "failed to create ext2 file system"
43 mount -oloop,$opts "$fs" "$where" || skip=1
44 echo test > "$where"/f || skip=1
45 test -s "$where"/f || skip=1
47 test $skip = 1 &&
48 skip_ "insufficient mount/ext2 support"
51 make_fs noxattr nouser_xattr
52 make_fs xattr user_xattr
54 # testing xattr name-value pair
55 xattr_name="user.foo"
56 xattr_value="bar"
57 xattr_pair="$xattr_name=\"$xattr_value\""
59 echo test > xattr/a || framework_failure_
60 getfattr -d xattr/a >out_a || skip_ "failed to get xattr of file"
61 grep -F "$xattr_pair" out_a >/dev/null && framework_failure_
62 setfattr -n "$xattr_name" -v "$xattr_value" xattr/a >out_a \
63 || skip_ "failed to set xattr of file"
64 getfattr -d xattr/a >out_a || skip_ "failed to get xattr of file"
65 grep -F "$xattr_pair" out_a >/dev/null \
66 || skip_ "failed to set xattr of file"
69 # This should pass without diagnostics
70 cp -a xattr/a noxattr/ 2>err || fail=1
71 test -s noxattr/a || fail=1 # destination file must not be empty
72 test -s err && fail=1 # there must be no stderr output
74 rm -f err noxattr/a
76 # This should pass without diagnostics (new file)
77 cp --preserve=all xattr/a noxattr/ 2>err || fail=1
78 test -s noxattr/a || fail=1 # destination file must not be empty
79 test -s err && fail=1 # there must be no stderr output
81 # This should pass without diagnostics (existing file)
82 cp --preserve=all xattr/a noxattr/ 2>err || fail=1
83 test -s noxattr/a || fail=1 # destination file must not be empty
84 test -s err && fail=1 # there must be no stderr output
86 rm -f err noxattr/a
88 # This should fail with coresponding diagnostics
89 cp -a --preserve=xattr xattr/a noxattr/ 2>err && fail=1
90 if grep '^#define USE_XATTR 1' $CONFIG_HEADER > /dev/null; then
91 cat <<\EOF > exp
92 cp: setting attributes for `noxattr/a': Operation not supported
93 EOF
94 else
95 cat <<\EOF > exp
96 cp: cannot preserve extended attributes, cp is built without xattr support
97 EOF
100 compare exp err || fail=1
102 rm -f err noxattr/a
104 # This should pass without diagnostics
105 mv xattr/a noxattr/ 2>err || fail=1
106 test -s noxattr/a || fail=1 # destination file must not be empty
107 test -s err && fail=1 # there must be no stderr output
109 Exit $fail