1af8fb121bac5124df7e3c25dbe9f8f039b46c13
[platform/upstream/coreutils.git] / tests / mv / hard-2
1 #!/bin/sh
2 # Ensure that moving hard-linked arguments onto existing destinations works.
3 # Likewise when using cp --preserve=link.
4
5 if test "$VERBOSE" = yes; then
6   set -x
7   mv --version
8   cp --version
9 fi
10
11 . $srcdir/../envvar-check
12 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
13
14 pwd=`pwd`
15 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
16 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
17 trap '(exit $?); exit $?' 1 2 13 15
18
19 framework_failure=0
20 mkdir -p $tmp || framework_failure=1
21 cd $tmp || framework_failure=1
22 mkdir dst || framework_failure=1
23 (cd dst && touch a b c) || framework_failure=1
24 touch a || framework_failure=1
25 ln a b || framework_failure=1
26 ln a c || framework_failure=1
27
28 if test $framework_failure = 1; then
29   echo "$0: failure in testing framework" 1>&2
30   (exit 1); exit 1
31 fi
32
33 fail=0
34
35 # ======================================
36 cp --preserve=link a b c dst || fail=1
37 # The source files must remain.
38 test -f a || fail=1
39 test -f b || fail=1
40 test -f c || fail=1
41 cd dst
42
43 # Three destination files must exist.
44 test -f a || fail=1
45 test -f b || fail=1
46 test -f c || fail=1
47
48 # The three i-node numbers must be the same.
49 ia=`ls -i a|sed 's/ a//'`
50 ib=`ls -i b|sed 's/ b//'`
51 ic=`ls -i c|sed 's/ c//'`
52 test $ia = $ib || fail=1
53 test $ia = $ic || fail=1
54
55 cd ..
56 rm -f dst/[abc]
57 (cd dst && touch a b c)
58
59 # ======================================
60 mv a b c dst || fail=1
61
62 # The source files must be gone.
63 test -f a && fail=1
64 test -f b && fail=1
65 test -f c && fail=1
66 cd dst
67
68 # Three destination files must exist.
69 test -f a || fail=1
70 test -f b || fail=1
71 test -f c || fail=1
72
73 # The three i-node numbers must be the same.
74 ia=`ls -i a|sed 's/ a//'`
75 ib=`ls -i b|sed 's/ b//'`
76 ic=`ls -i c|sed 's/ c//'`
77 test $ia = $ib || fail=1
78 test $ia = $ic || fail=1
79
80 (exit $fail); exit $fail