Fix copy-pasto in the patch to allow background writer to run during
[PostgreSQL.git] / config / mkinstalldirs
blobc51e3ed2b9ac3a06c34673063eee85bb462c7c6a
1 #! /bin/sh
2 # mkinstalldirs --- make directory hierarchy
4 # $PostgreSQL$
6 scriptversion=2005-02-02.21
8 # Original author: Noah Friedman <friedman@prep.ai.mit.edu>
9 # Created: 1993-05-16
10 # Public domain.
12 # This file is maintained in Automake, please report
13 # bugs to <bug-automake@gnu.org> or send patches to
14 # <automake-patches@gnu.org>.
16 errstatus=0
17 dirmode=""
19 usage="\
20 Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
22 Create each directory DIR (with mode MODE, if specified), including all
23 leading file name components.
25 Report bugs to <bug-automake@gnu.org>."
27 # process command line arguments
28 while test $# -gt 0 ; do
29 case $1 in
30 -h | --help | --h*) # -h for help
31 echo "$usage"
32 exit $?
34 -m) # -m PERM arg
35 shift
36 test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
37 dirmode=$1
38 shift
40 --version)
41 echo "$0 $scriptversion"
42 exit $?
44 --) # stop option processing
45 shift
46 break
48 -*) # unknown option
49 echo "$usage" 1>&2
50 exit 1
52 *) # first non-opt arg
53 break
55 esac
56 done
58 for file
60 if test -d "$file"; then
61 shift
62 else
63 break
65 done
67 case $# in
68 0) exit 0 ;;
69 esac
71 # Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and
72 # mkdir -p a/c at the same time, both will detect that a is missing,
73 # one will create a, then the other will try to create a and die with
74 # a "File exists" error. This is a problem when calling mkinstalldirs
75 # from a parallel make. We use --version in the probe to restrict
76 # ourselves to GNU mkdir, which is thread-safe.
77 case $dirmode in
78 '')
79 if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
80 echo "mkdir -p -- $*"
81 exec mkdir -p -- "$@"
82 else
83 # On NextStep and OpenStep, the `mkdir' command does not
84 # recognize any option. It will interpret all options as
85 # directories to create, and then abort because `.' already
86 # exists.
87 test -d ./-p && rmdir ./-p
88 test -d ./--version && rmdir ./--version
92 if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
93 test ! -d ./--version; then
94 echo "mkdir -m $dirmode -p -- $*"
95 exec mkdir -m "$dirmode" -p -- "$@"
96 else
97 # Clean up after NextStep and OpenStep mkdir.
98 for d in ./-m ./-p ./--version "./$dirmode";
100 test -d $d && rmdir $d
101 done
104 esac
106 for file
108 set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
109 shift
111 pathcomp=
112 for d
114 pathcomp="$pathcomp$d"
115 case $pathcomp in
116 -*) pathcomp=./$pathcomp ;;
117 esac
119 if test ! -d "$pathcomp"; then
120 echo "mkdir $pathcomp"
122 mkdir "$pathcomp" || lasterr=$?
124 if test ! -d "$pathcomp"; then
125 errstatus=$lasterr
126 else
127 if test ! -z "$dirmode"; then
128 echo "chmod $dirmode $pathcomp"
129 lasterr=""
130 chmod "$dirmode" "$pathcomp" || lasterr=$?
132 if test ! -z "$lasterr"; then
133 errstatus=$lasterr
139 pathcomp="$pathcomp/"
140 done
141 done
143 exit $errstatus
145 # Local Variables:
146 # mode: shell-script
147 # sh-indentation: 2
148 # eval: (add-hook 'write-file-hooks 'time-stamp)
149 # time-stamp-start: "scriptversion="
150 # time-stamp-format: "%:y-%02m-%02d.%02H"
151 # time-stamp-end: "$"
152 # End: