summaryrefslogtreecommitdiff
path: root/tests/mkdir/perm
blob: fe78cb1eb84d3fba09c71a26a6cb6b889b2d70d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
# Verify that mkdir's `-m MODE' option works properly
# with various umask settings.

if test "$VERBOSE" = yes; then
  set -x
  mkdir --version
fi

pwd=`pwd`
tmp=perm.$$
trap 'status=$?; cd $pwd; rm -rf $tmp && exit $status' 0
trap '(exit $?); exit' 1 2 13 15

framework_failure=0
mkdir $tmp || framework_failure=1
cd $tmp || framework_failure=1

if test $framework_failure = 1; then
  echo 'failure in testing framework'
  (exit 1); exit
fi

fail=0

# umask   -m option   resulting perm
tests='
    000  :            :drwxrwxrwx:
    000  :   -m 016   :d-----xrw-:
    077  :            :drwx------:
    050  :            :drwx-w-rwx:
    050  :   -m 312   :d-wx--x-w-:
    160  :            :drw---xrwx:
    '

old_IFS=$IFS
IFS=':
'
set - $tests
IFS=$old_IFS

while :; do
  case $# in 0|1|2) break;; esac

  umask=$1 mode=$2 expected_perms=$3
  shift; shift; shift
  umask $umask
  mkdir $mode d || fail=1

  actual_perms=`ls -ld d | sed 's/ .*//'`
  test "$expected_perms" = "$actual_perms" \
    || { fail=1; echo expected $expected_perms, got $actual_perms; }
  rmdir d || fail=1
done

(exit $fail); exit