tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / cp / link-preserve
1 #!/bin/sh
2 # ensure that `cp -d' preserves hard-links between command line arguments
3 # ensure that --preserve=links works with -RH and -RL
4
5 # Copyright (C) 2001, 2002, 2004, 2006-2009 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 3 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, see <http://www.gnu.org/licenses/>.
19
20 if test "$VERBOSE" = yes; then
21   set -x
22   cp --version
23 fi
24
25 . $srcdir/test-lib.sh
26
27 touch a || framework_failure
28 ln a b || framework_failure
29 mkdir c || framework_failure
30 cp -d a b c || framework_failure
31 test -f c/a || framework_failure
32 test -f c/b || framework_failure
33
34
35 a_inode=`ls -i c/a|sed 's,c/.*,,'`
36 b_inode=`ls -i c/b|sed 's,c/.*,,'`
37 test "$a_inode" = "$b_inode" || fail=1
38 # --------------------------------------
39
40 rm -rf a b c
41 touch a
42 ln -s a b
43 mkdir c
44 cp --preserve=links -R -H a b c
45 a_inode=`ls -i c/a|sed 's,c/.*,,'`
46 b_inode=`ls -i c/b|sed 's,c/.*,,'`
47 test "$a_inode" = "$b_inode" || fail=1
48 # --------------------------------------
49
50 # Ensure that -L makes cp follow the b->a symlink
51 # and translates to hard-linked a and b in the destination dir.
52 rm -rf a b c d; mkdir d; (cd d; touch a; ln -s a b)
53 cp --preserve=links -R -L d c
54 a_inode=`ls -i c/a|sed 's,c/.*,,'`
55 b_inode=`ls -i c/b|sed 's,c/.*,,'`
56 test "$a_inode" = "$b_inode" || fail=1
57 # --------------------------------------
58
59 # Same as above, but starting with a/b hard linked.
60 rm -rf a b c d; mkdir d; (cd d; touch a; ln a b)
61 cp --preserve=links -R -L d c
62 a_inode=`ls -i c/a|sed 's,c/.*,,'`
63 b_inode=`ls -i c/b|sed 's,c/.*,,'`
64 test "$a_inode" = "$b_inode" || fail=1
65 # --------------------------------------
66
67 # Ensure that --no-preserve=links works.
68 rm -rf a b c d; mkdir d; (cd d; touch a; ln a b)
69 cp -dR --no-preserve=links d c
70 a_inode=`ls -i c/a|sed 's,c/.*,,'`
71 b_inode=`ls -i c/b|sed 's,c/.*,,'`
72 test "$a_inode" = "$b_inode" && fail=1
73 # --------------------------------------
74
75 # Ensure that -d still preserves hard links.
76 rm -rf a b c d
77 touch a; ln a b
78 mkdir c
79 cp -d a b c
80 a_inode=`ls -i c/a|sed 's,c/.*,,'`
81 b_inode=`ls -i c/b|sed 's,c/.*,,'`
82 test "$a_inode" = "$b_inode" || fail=1
83 # --------------------------------------
84
85 # Ensure that --no-preserve=mode works
86 rm -rf a b c d
87 touch a; chmod 731 a
88 umask 077
89 cp -a --no-preserve=mode a b
90 mode=`ls -l b|cut -b-10`
91 test "$mode" = "-rwx------" || fail=1
92 umask 022
93 # --------------------------------------
94
95 Exit $fail