7c8a3404c811065b6a80d6b89bce4dcbbd057929
[platform/upstream/coreutils.git] / tests / mv / into-self-2
1 #!/bin/sh
2 # Force mv to use the copying code.
3 # Consider the case where SRC and DEST are on different
4 # partitions and DEST is a symlink to SRC.
5
6 if test "$VERBOSE" = yes; then
7   set -x
8   mv --version
9 fi
10
11 . $srcdir/setup
12 . $srcdir/../envvar-check
13
14 if test -z "$other_partition_tmpdir"; then
15   exit 77
16 fi
17
18 file="$other_partition_tmpdir/file"
19 symlink=symlink
20
21 fail=0
22
23 trap 'rm -fr out out2 exp $file $symlink $other_partition_tmpdir; exit $fail' \
24   0 1 2 3 15
25
26 framework_failure=0
27 rm -f $file $symlink || framework_failure=1
28 echo whatever > $file || framework_failure=1
29 ln -s $file $symlink || framework_failure=1
30
31 if test $framework_failure = 1; then
32   echo 'failure in testing framework'
33   exit 1
34 fi
35
36 # Make sure we get English translations.
37 . $srcdir/../lang-default
38
39 # This mv command should exit nonzero.
40 mv $symlink $file > out 2>&1 && fail=1
41
42 # This should succeed.
43 mv $file $symlink || fail=1
44
45 sed \
46    -e "s,mv:,XXX:," \
47    -e "s,$file,YYY," \
48    -e "s,$symlink,ZZZ," \
49   out > out2
50
51 cat > exp <<\EOF
52 XXX: `ZZZ' and `YYY' are the same file
53 EOF
54 #'
55
56 cmp out2 exp || fail=1
57 test $fail = 1 && diff out2 exp 2> /dev/null
58
59 exit $fail