Tizen 2.0 Release
[external/tizen-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 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   cp --version
25 fi
26
27 . $srcdir/../envvar-check
28 . $srcdir/../lang-default
29
30 pwd=`pwd`
31 t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$
32 trap 'status=$?; cd "$pwd" && rm -rf $t0 && exit $status' 0
33 trap '(exit $?); exit' 1 2 13 15
34
35 framework_failure=0
36 mkdir -p $tmp || framework_failure=1
37 cd $tmp || framework_failure=1
38 touch a || framework_failure=1
39 ln a b || framework_failure=1
40 mkdir c || framework_failure=1
41 cp -d a b c || framework_failure=1
42 test -f c/a || framework_failure=1
43 test -f c/b || framework_failure=1
44
45 if test $framework_failure = 1; then
46   echo 'failure in testing framework' 1>&2
47   (exit 1); exit 1
48 fi
49
50 fail=0
51
52 a_inode=`ls -i c/a|sed 's,c/.*,,'`
53 b_inode=`ls -i c/b|sed 's,c/.*,,'`
54 test "$a_inode" = "$b_inode" || fail=1
55 # --------------------------------------
56
57 rm -rf a b c
58 touch a
59 ln -s a b
60 mkdir c
61 cp --preserve=links -R -H a b 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 rm -rf a b c d
68 mkdir d
69 (cd d; touch a; ln -s a b)
70 cp --preserve=links -R -L d c
71 a_inode=`ls -i c/a|sed 's,c/.*,,'`
72 b_inode=`ls -i c/b|sed 's,c/.*,,'`
73 test "$a_inode" = "$b_inode" || fail=1
74 # --------------------------------------
75
76 # Ensure that --no-preserve=links works.
77 rm -rf a b c d
78 mkdir d
79 (cd d; touch a; ln a b)
80 cp -dR --no-preserve=links d c
81 a_inode=`ls -i c/a|sed 's,c/.*,,'`
82 b_inode=`ls -i c/b|sed 's,c/.*,,'`
83 test "$a_inode" = "$b_inode" && fail=1
84 # --------------------------------------
85
86 # Ensure that -d still preserves hard links.
87 rm -rf a b c d
88 touch a; ln a b
89 mkdir c
90 cp -d a b c
91 a_inode=`ls -i c/a|sed 's,c/.*,,'`
92 b_inode=`ls -i c/b|sed 's,c/.*,,'`
93 test "$a_inode" = "$b_inode" || fail=1
94 # --------------------------------------
95
96 # Ensure that --no-preserve=mode works
97 rm -rf a b c d
98 touch a; chmod 731 a
99 umask 077
100 cp -a --no-preserve=mode a b
101 set _ `ls -l b`; shift; mode=$1
102 test "$mode" = "-rwx------" || fail=1
103 umask 022
104 # --------------------------------------
105
106 (exit $fail); exit $fail