007ce938cb16ef4719f4a631924849e442528c0f
[platform/upstream/coreutils.git] / tests / cp / special-bits
1 #!/bin/sh
2 # make sure `cp -p' preserves special bits
3 # This works only when run as root.
4
5 # This test would fail due to a bug introduced in 4.0y.
6 # The bug was fixed in 4.0z.
7
8 if test "$VERBOSE" = yes; then
9   set -x
10   cp --version
11 fi
12
13 PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
14
15 pwd=`pwd`
16 t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$
17 trap 'status=$?; cd $pwd; rm -rf $t0 && exit $status' 0
18 trap '(exit $?); exit' 1 2 13 15
19
20 framework_failure=0
21 mkdir -p $tmp || framework_failure=1
22 cd $tmp || framework_failure=1
23
24 touch a b || framework_failure=1
25 chmod u+sx,go= a || framework_failure=1
26 chmod u=rwx,g=sx,o= b || framework_failure=1
27
28 if test $framework_failure = 1; then
29   echo 'failure in testing framework'
30   exit 1
31 fi
32
33 fail=0
34
35 cp -p a a2 || fail=1
36 set _ `ls -l a`; shift; p1=$1
37 set _ `ls -l a2`; shift; p2=$1
38 test $p1 = $p2 || fail=1
39
40 cp -p b b2 || fail=1
41 set _ `ls -l b`; shift; p1=$1
42 set _ `ls -l b2`; shift; p2=$1
43 test $p1 = $p2 || fail=1
44
45 (exit $fail); exit $fail