Add/fix copyright notices and adjust to latest GNU FDL.
[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 # Copyright (C) 2003 Free Software Foundation, Inc.
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
21
22 if test "$VERBOSE" = yes; then
23   set -x
24   mv --version
25   cp --version
26 fi
27
28 . $srcdir/../envvar-check
29 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
30
31 pwd=`pwd`
32 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
33 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
34 trap '(exit $?); exit $?' 1 2 13 15
35
36 framework_failure=0
37 mkdir -p $tmp || framework_failure=1
38 cd $tmp || framework_failure=1
39 mkdir dst || framework_failure=1
40 (cd dst && touch a b c) || framework_failure=1
41 touch a || framework_failure=1
42 ln a b || framework_failure=1
43 ln a c || framework_failure=1
44
45 if test $framework_failure = 1; then
46   echo "$0: failure in testing framework" 1>&2
47   (exit 1); exit 1
48 fi
49
50 fail=0
51
52 # ======================================
53 cp --preserve=link a b c dst || fail=1
54 # The source files must remain.
55 test -f a || fail=1
56 test -f b || fail=1
57 test -f c || fail=1
58 cd dst
59
60 # Three destination files must exist.
61 test -f a || fail=1
62 test -f b || fail=1
63 test -f c || fail=1
64
65 # The three i-node numbers must be the same.
66 ia=`ls -i a|sed 's/ a//'`
67 ib=`ls -i b|sed 's/ b//'`
68 ic=`ls -i c|sed 's/ c//'`
69 test $ia = $ib || fail=1
70 test $ia = $ic || fail=1
71
72 cd ..
73 rm -f dst/[abc]
74 (cd dst && touch a b c)
75
76 # ======================================
77 mv a b c dst || fail=1
78
79 # The source files must be gone.
80 test -f a && fail=1
81 test -f b && fail=1
82 test -f c && fail=1
83 cd dst
84
85 # Three destination files must exist.
86 test -f a || fail=1
87 test -f b || fail=1
88 test -f c || fail=1
89
90 # The three i-node numbers must be the same.
91 ia=`ls -i a|sed 's/ a//'`
92 ib=`ls -i b|sed 's/ b//'`
93 ic=`ls -i c|sed 's/ c//'`
94 test $ia = $ib || fail=1
95 test $ia = $ic || fail=1
96
97 (exit $fail); exit $fail