208
220
echo "$0: $dstarg: Is a directory" >&2
211
dst=$dst/`basename "$src"`
224
dst=$dstdir/`basename "$src"`
227
# Prefer dirname, but fall back on a substitute if dirname fails.
229
(dirname "$dst") 2>/dev/null ||
230
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
231
X"$dst" : 'X\(//\)[^/]' \| \
232
X"$dst" : 'X\(//\)$' \| \
233
X"$dst" : 'X\(/\)' \| \
234
. : '\(.\)' 2>/dev/null ||
236
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
237
/^X\(\/\/\)[^/].*/{ s//\1/; q; }
238
/^X\(\/\/\)$/{ s//\1/; q; }
239
/^X\(\/\).*/{ s//\1/; q; }
215
# This sed command emulates the dirname command.
216
dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
218
# Make sure that the destination directory exists.
220
# Skip lots of stat calls in the usual case.
221
if test ! -d "$dstdir"; then
224
IFS="${IFS-$defaultIFS}"
227
# Some sh's can't handle IFS=/ for some reason.
229
set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
235
while test $# -ne 0 ; do
248
obsolete_mkdir_used=false
250
if test $dstdir_status != 0; then
254
if $mkdirprog -m $test_mode -p -- / >/dev/null 2>&1; then
257
# Remove any dirs left behind by ancient mkdir implementations.
258
rmdir ./-m "$test_mode" ./-p ./-- 2>/dev/null
265
# With -d, create the new directory with the user-specified mode.
266
# Otherwise, create it using the same intermediate mode that
267
# mkdir -p would use when creating intermediate directories.
268
# POSIX says that this mode is "$(umask -S),u+wx", so use that
271
if test -n "$dir_arg"; then
274
case $intermediate_mode in
276
if umask_S=`(umask -S) 2>/dev/null`; then
277
intermediate_mode=$umask_S,u+wx
279
intermediate_mode=$test_mode
282
mkdir_mode=$intermediate_mode
285
$mkdirprog -m "$mkdir_mode" -p -- "$dstdir"
290
# mkdir does not conform to POSIX, or it failed possibly due to
291
# a race condition. Create the directory the slow way, step by
292
# step, checking for races as we go.
302
if (set -f) 2>/dev/null; then
311
$posix_glob && set -f
238
if test ! -d "$pathcomp"; then
239
$mkdirprog "$pathcomp"
240
# mkdir can fail with a `File exist' error in case several
241
# install-sh are creating the directory concurrently. This
243
test -d "$pathcomp" || exit
314
$posix_glob && set +f
319
test "x$d" = x && continue
322
if test ! -d "$pathcomp"; then
323
$mkdirprog "$pathcomp"
324
# Don't fail if two instances are running concurrently.
325
test -d "$pathcomp" || exit 1
329
obsolete_mkdir_used=true
249
333
if test -n "$dir_arg"; then
250
$doit $mkdircmd "$dst" \
251
&& { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
252
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
253
&& { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
254
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
334
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
335
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
336
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
337
test -z "$chmodcmd" || $doit $chmodcmd "$mode" "$dst"; } || exit 1
257
dstfile=`basename "$dst"`
259
340
# Make a couple of temp file names in the proper directory.
260
341
dsttmp=$dstdir/_inst.$$_
276
356
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
277
357
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
278
358
&& { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
279
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
359
&& { test -z "$chmodcmd" || $doit $chmodcmd "$mode" "$dsttmp"; } &&
281
361
# Now rename the file to the real destination.
282
{ $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
362
{ $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
284
364
# The rename failed, perhaps because mv can't rename something else
285
365
# to itself, or perhaps because mv is so ancient that it does not
291
371
# reasons. In this case, the final cleanup might fail but the new
292
372
# file should still install successfully.
294
if test -f "$dstdir/$dstfile"; then
295
$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
296
|| $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
374
if test -f "$dst"; then
375
$doit $rmcmd -f "$dst" 2>/dev/null \
376
|| { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \
377
&& { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\
298
echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
379
echo "$0: cannot unlink or rename $dst" >&2