Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / mkdir / parents
1 #!/bin/sh
2 # make sure mkdir's -p options works properly
3
4 # Copyright (C) 2000, 2004, 2006 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 if test "$VERBOSE" = yes; then
22   set -x
23   mkdir --version
24 fi
25
26 pwd=`pwd`
27 tmp=parents-$$
28 trap 'status=$?; cd "$pwd" && rm -rf $tmp && exit $status' 0
29 trap '(exit $?); exit' 1 2 13 15
30
31 framework_failure=0
32
33 # Record absolute path of srcdir.
34 cd $srcdir || framework_failure=1
35 abs_srcdir=`pwd`
36
37 cd "$pwd" || framework_failure=1
38 mkdir $tmp || framework_failure=1
39 cd $tmp || framework_failure=1
40 mkdir -m 700 e-dir || framework_failure=1
41
42 if test $framework_failure = 1; then
43   echo 'failure in testing framework'
44   (exit 1); exit 1
45 fi
46
47 . "$abs_srcdir/../setgid-check"
48
49 fail=0
50
51 # Make sure `mkdir -p existing-dir' succeeds
52 # and that `mkdir existing-dir' fails.
53 mkdir -p e-dir || fail=1
54 mkdir e-dir > /dev/null 2>&1 && fail=1
55
56 # Create an existing directory.
57 umask 077
58 mode_str=drwxr-x-wx
59 mode_arg=`"$abs_srcdir/../rwx-to-mode" $mode_str`
60 mkdir -m $mode_arg a || fail=1
61
62 # this `mkdir -p ...' shouldn't change perms of existing dir `a'.
63 d_mode_str=drwx-w--wx
64 d_mode_arg=`"$abs_srcdir/../rwx-to-mode" $d_mode_str`
65 mkdir -p -m $d_mode_arg a/b/c/d
66
67 # Make sure the permissions of `a' haven't been changed.
68 p=`ls -ld a|sed 's/ .*//'`; case $p in $mode_str);; *) fail=1;; esac
69 # `b's and `c's should reflect the umask
70 p=`ls -ld a/b|sed 's/ .*//'`; case $p in drwx------);; *) fail=1;; esac
71 p=`ls -ld a/b/c|sed 's/ .*//'`; case $p in drwx------);; *) fail=1;; esac
72
73 # `d's perms are determined by the -m argument.
74 p=`ls -ld a/b/c/d|sed 's/ .*//'`; case $p in $d_mode_str);; *) fail=1;; esac
75
76 (exit $fail); exit $fail