Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / mv / part-fail
1 #!/bin/sh
2 # Make sure we give a sensible diagnostic when a cross-device `mv'
3 # fails, e.g., because the destination cannot be unlinked.
4 # This is a bit fragile since it relies on the string used
5 # for EPERM: `permission denied'.
6
7 # Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
8
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 2 of the License, or
12 # (at your option) any later version.
13
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.
18
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 # 02110-1301, USA.
23
24 if test "$VERBOSE" = yes; then
25   set -x
26   mv --version
27 fi
28
29 . $srcdir/../other-fs-tmpdir
30 . $srcdir/../envvar-check
31 . $srcdir/../lang-default
32 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
33
34 pwd=`pwd`
35 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
36 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
37 trap '(exit $?); exit' 1 2 13 15
38
39 if test -z "$other_partition_tmpdir"; then
40   (exit 77); exit 77
41 fi
42 t0="$t0 $other_partition_tmpdir"
43
44 framework_failure=0
45 mkdir -p $tmp || framework_failure=1
46 cd $tmp || framework_failure=1
47 touch k $other_partition_tmpdir/k || framework_failure=1
48 chmod u-w $other_partition_tmpdir || framework_failure=1
49
50 if test $framework_failure = 1; then
51   echo "$0: failure in testing framework" 1>&2
52   (exit 1); exit 1
53 fi
54
55 fail=0
56
57 mv -f k $other_partition_tmpdir 2> out && fail=1
58 cat <<EOF > exp
59 mv: inter-device move failed: \`k' to \`$other_partition_tmpdir/k'; unable to remove target: Permission denied
60 EOF
61
62 # On some (less-compliant) systems, we get EPERM in this case.
63 # Accept either diagnostic.
64 cat <<EOF > exp2
65 mv: cannot move \`k' to \`$other_partition_tmpdir/k': Permission denied
66 EOF
67
68 if cmp out exp >/dev/null 2>&1; then
69   :
70 else
71   if cmp out exp2; then
72     :
73   else
74     fail=1
75   fi
76 fi
77 test $fail = 1 && diff out exp 2> /dev/null
78
79 (exit $fail); exit $fail