maint: avoid a syntax check failure
[coreutils.git] / tests / mv / sticky-to-xpart.sh
blobc921503e08a7768773aedb44e6fc3a9d5b1465e4
1 #!/bin/sh
2 # A cross-partition move of a file in a sticky tmpdir and owned by
3 # someone else would evoke an invalid diagnostic:
4 # mv: cannot remove 'x': Operation not permitted
5 # Affects coreutils-6.0-6.9.
7 # Copyright (C) 2007-2017 Free Software Foundation, Inc.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
23 print_ver_ mv
24 require_root_
26 cleanup_() { rm -rf "$other_partition_tmpdir"; }
27 . "$abs_srcdir/tests/other-fs-tmpdir"
29 # Set up to run a test where non-root user tries to move a root-owned
30 # file from a sticky tmpdir to a directory owned by that user on
31 # a different partition.
33 mkdir t || framework_failure_
34 chmod a=rwx,o+t t || framework_failure_
35 echo > t/root-owned || framework_failure_
36 chmod a+r t/root-owned || framework_failure_
37 chown "$NON_ROOT_USERNAME" "$other_partition_tmpdir" || framework_failure_
39 # We have to allow $NON_ROOT_USERNAME access to ".".
40 chmod go+x . || framework_failure_
43 # Ensure that $NON_ROOT_USERNAME can access the required version of mv.
44 version=$(
45 chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
46 mv --version |
47 sed -n '1s/.* //p'
49 case $version in
50 $PACKAGE_VERSION) ;;
51 *) skip_ "cannot access just-built mv as user $NON_ROOT_USERNAME";;
52 esac
54 chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
55 mv t/root-owned "$other_partition_tmpdir" 2> out-t && fail=1
57 # On some systems, we get 'Not owner'. Convert it.
58 # On other systems (HPUX), we get 'Permission denied'. Convert it, too.
59 onp='Operation not permitted'
60 sed "s/Not owner/$onp/;s/Permission denied/$onp/" out-t > out
62 cat <<\EOF > exp
63 mv: cannot remove 't/root-owned': Operation not permitted
64 EOF
66 compare exp out || fail=1
68 Exit $fail