Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / cp / cp-parents
1 #!/bin/sh
2 # cp -R --parents dir-specified-with-trailing-slash/ other-dir
3 # would get a failed assertion.
4
5 # Copyright (C) 2000, 2002, 2004, 2005, 2006, 2007 Free Software
6 # Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
22
23 if test "$VERBOSE" = yes; then
24   set -x
25   mv --version
26 fi
27
28 umask 022
29
30 pwd=`pwd`
31 t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$
32 trap 'status=$?; cd "$pwd" && exec 1>&2; rm -rf $t0 && exit $status' 0
33 trap '(exit $?); exit' 1 2 13 15
34
35 framework_failure=0
36
37 # Record absolute path of srcdir and cd back to current dir.
38 cd $srcdir || framework_failure=1
39 abs_srcdir=`pwd`
40 cd "$pwd" || framework_failure=1
41
42 . $srcdir/../envvar-check
43 . $srcdir/../umask-check
44
45 mkdir -p $tmp || framework_failure=1
46 cd $tmp || framework_failure=1
47
48 . "$abs_srcdir/../setgid-check"
49
50 mkdir foo bar || framework_failure=1
51 mkdir -p a/b/c d e || framework_failure=1
52 touch f || framework_failure=1
53
54 if test $framework_failure = 1; then
55   echo 'failure in testing framework'
56   exit 1
57 fi
58
59 fail=0
60
61 # With 4.0.37 and earlier (back to when?), this would fail
62 # with the failed assertion from dirname.c.
63 cp -R --parents foo/ bar || fail=1
64
65 # Exercise the make_path and re_protect code in cp.c.
66 # FIXME: compare verbose output with expected output.
67 cp --verbose -a --parents a/b/c d > /dev/null 2>&1 || fail=1
68 test -d d/a/b/c || fail=1
69
70 # With 6.7 and earlier, cp --parents f/g d would mistakenly create a
71 # directory d/f, even though f is a regular file.
72 cp --parents f/g d 2>/dev/null && fail=1
73 test -d d/f && fail=1
74
75 # Check that re_protect works.
76 chmod go=w d/a
77 cp -a --parents d/a/b/c e || fail=1
78 p=`ls -ld e/d|sed 's/ .*//'`; case $p in drwxr-xr-x);; *) fail=1;; esac
79 p=`ls -ld e/d/a|sed 's/ .*//'`; case $p in drwx-w--w-);; *) fail=1;; esac
80 p=`ls -ld e/d/a/b/c|sed 's/ .*//'`; case $p in drwxr-xr-x);; *) fail=1;; esac
81
82 (exit $fail); exit $fail