8f97cb515fd4ece8958cfbdf2955edbe6d18fcab
[platform/upstream/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 if test "$VERBOSE" = yes; then
6   set -x
7   mv --version
8 fi
9
10 umask 022
11
12 pwd=`pwd`
13 t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$
14 trap 'status=$?; cd $pwd; exec 1>&2; rm -rf $t0 && exit $status' 0
15 trap '(exit $?); exit' 1 2 13 15
16
17 framework_failure=0
18
19 # Record absolute path of srcdir and cd back to current dir.
20 cd $srcdir || framework_failure=1
21 abs_srcdir=`pwd`
22 cd $pwd || framework_failure=1
23
24 . $srcdir/../envvar-check
25 . $srcdir/../umask-check
26
27 mkdir -p $tmp || framework_failure=1
28 cd $tmp || framework_failure=1
29
30 . $abs_srcdir/../setgid-check
31
32 mkdir foo bar || framework_failure=1
33 mkdir -p a/b/c d e || framework_failure=1
34
35 if test $framework_failure = 1; then
36   echo 'failure in testing framework'
37   exit 1
38 fi
39
40 fail=0
41
42 # With 4.0.37 and earlier (back to when?), this would fail
43 # with the failed assertion from dirname.c.
44 cp -R --parents foo/ bar || fail=1
45
46 # Exercise the make_path and re_protect code in cp.c.
47 # FIXME: compare verbose output with expected output.
48 cp --verbose -a --parents a/b/c d > /dev/null 2>&1 || fail=1
49 test -d d/a/b/c || fail=1
50
51 # Check that re_protect works.
52 chmod go=w d/a
53 cp -a --parents d/a/b/c e || fail=1
54 p=`ls -ld e/d|sed 's/ .*//'`; case $p in drwxr-xr-x);; *) fail=1;; esac
55 p=`ls -ld e/d/a|sed 's/ .*//'`; case $p in drwx-w--w-);; *) fail=1;; esac
56 p=`ls -ld e/d/a/b/c|sed 's/ .*//'`; case $p in drwxr-xr-x);; *) fail=1;; esac
57
58 (exit $fail); exit $fail