A few more symlink-related fixes. Fix a bug triggered by cp
[coreutils/ericb.git] / tests / cp / cp-parents
blob274f47d8df71c88833bea3e33f7efa4219cae42c
1 #!/bin/sh
2 # cp -R --parents dir-specified-with-trailing-slash/ other-dir
3 # would get a failed assertion.
5 # Copyright (C) 2000, 2002, 2004, 2005, 2006, 2007 Free Software
6 # Foundation, Inc.
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.
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.
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.
23 if test "$VERBOSE" = yes; then
24 set -x
25 mv --version
28 umask 022
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
35 framework_failure=0
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
42 . $srcdir/../envvar-check
43 . $srcdir/../umask-check
45 mkdir -p $tmp || framework_failure=1
46 cd $tmp || framework_failure=1
48 . "$abs_srcdir/../setgid-check"
50 mkdir foo bar || framework_failure=1
51 mkdir -p a/b/c d e g || framework_failure=1
52 ln -s d/a sym || framework_failure=1
53 touch f || framework_failure=1
55 if test $framework_failure = 1; then
56 echo 'failure in testing framework'
57 exit 1
60 fail=0
62 # With 4.0.37 and earlier (back to when?), this would fail
63 # with the failed assertion from dirname.c.
64 cp -R --parents foo/ bar || fail=1
66 # Exercise the make_path and re_protect code in cp.c.
67 # FIXME: compare verbose output with expected output.
68 cp --verbose -a --parents a/b/c d > /dev/null 2>&1 || fail=1
69 test -d d/a/b/c || fail=1
71 # With 6.7 and earlier, cp --parents f/g d would mistakenly create a
72 # directory d/f, even though f is a regular file.
73 cp --parents f/g d 2>/dev/null && fail=1
74 test -d d/f && fail=1
76 # Check that re_protect works.
77 chmod go=w d/a
78 cp -a --parents d/a/b/c e || fail=1
79 cp -a --parents sym/b/c g || fail=1
80 p=`ls -ld e/d|cut -b-10`; case $p in drwxr-xr-x);; *) fail=1;; esac
81 p=`ls -ld e/d/a|cut -b-10`; case $p in drwx-w--w-);; *) fail=1;; esac
82 p=`ls -ld g/sym|cut -b-10`; case $p in drwx-w--w-);; *) fail=1;; esac
83 p=`ls -ld e/d/a/b/c|cut -b-10`; case $p in drwxr-xr-x);; *) fail=1;; esac
84 p=`ls -ld g/sym/b/c|cut -b-10`; case $p in drwxr-xr-x);; *) fail=1;; esac
86 (exit $fail); exit $fail