Skip to content

Commit 691d927

Browse files
committed
Merge pull request git-for-windows#6 from dscho/ctrl-c
When interrupting Win32 processes, kill their child processes, too
2 parents 5f77858 + 89f6fc3 commit 691d927

File tree

10 files changed

+2953
-1149
lines changed

10 files changed

+2953
-1149
lines changed

install-sh

Lines changed: 107 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
# install - install a program, script, or datafile
33

4-
scriptversion=2013-12-25.23; # UTC
4+
scriptversion=2020-11-14.01; # UTC
55

66
# This originates from X11R5 (mit/util/scripts/install.sh), which was
77
# later released in X11R6 (xc/config/util/install.sh) with the
@@ -69,6 +69,11 @@ posix_mkdir=
6969
# Desired mode of installed file.
7070
mode=0755
7171

72+
# Create dirs (including intermediate dirs) using mode 755.
73+
# This is like GNU 'install' as of coreutils 8.32 (2020).
74+
mkdir_umask=22
75+
76+
backupsuffix=
7277
chgrpcmd=
7378
chmodcmd=$chmodprog
7479
chowncmd=
@@ -99,18 +104,28 @@ Options:
99104
--version display version info and exit.
100105
101106
-c (ignored)
102-
-C install only if different (preserve the last data modification time)
107+
-C install only if different (preserve data modification time)
103108
-d create directories instead of installing files.
104109
-g GROUP $chgrpprog installed files to GROUP.
105110
-m MODE $chmodprog installed files to MODE.
106111
-o USER $chownprog installed files to USER.
112+
-p pass -p to $cpprog.
107113
-s $stripprog installed files.
114+
-S SUFFIX attempt to back up existing files, with suffix SUFFIX.
108115
-t DIRECTORY install into DIRECTORY.
109116
-T report an error if DSTFILE is a directory.
110117
111118
Environment variables override the default commands:
112119
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
113120
RMPROG STRIPPROG
121+
122+
By default, rm is invoked with -f; when overridden with RMPROG,
123+
it's up to you to specify -f if you want it.
124+
125+
If -S is not specified, no backups are attempted.
126+
127+
Email bug reports to [email protected].
128+
Automake home page: https://www.gnu.org/software/automake/
114129
"
115130

116131
while test $# -ne 0; do
@@ -137,8 +152,13 @@ while test $# -ne 0; do
137152
-o) chowncmd="$chownprog $2"
138153
shift;;
139154

155+
-p) cpprog="$cpprog -p";;
156+
140157
-s) stripcmd=$stripprog;;
141158

159+
-S) backupsuffix="$2"
160+
shift;;
161+
142162
-t)
143163
is_target_a_directory=always
144164
dst_arg=$2
@@ -255,6 +275,10 @@ do
255275
dstdir=$dst
256276
test -d "$dstdir"
257277
dstdir_status=$?
278+
# Don't chown directories that already exist.
279+
if test $dstdir_status = 0; then
280+
chowncmd=""
281+
fi
258282
else
259283

260284
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
@@ -271,15 +295,18 @@ do
271295
fi
272296
dst=$dst_arg
273297

274-
# If destination is a directory, append the input filename; won't work
275-
# if double slashes aren't ignored.
298+
# If destination is a directory, append the input filename.
276299
if test -d "$dst"; then
277300
if test "$is_target_a_directory" = never; then
278301
echo "$0: $dst_arg: Is a directory" >&2
279302
exit 1
280303
fi
281304
dstdir=$dst
282-
dst=$dstdir/`basename "$src"`
305+
dstbase=`basename "$src"`
306+
case $dst in
307+
*/) dst=$dst$dstbase;;
308+
*) dst=$dst/$dstbase;;
309+
esac
283310
dstdir_status=0
284311
else
285312
dstdir=`dirname "$dst"`
@@ -288,27 +315,16 @@ do
288315
fi
289316
fi
290317

318+
case $dstdir in
319+
*/) dstdirslash=$dstdir;;
320+
*) dstdirslash=$dstdir/;;
321+
esac
322+
291323
obsolete_mkdir_used=false
292324

293325
if test $dstdir_status != 0; then
294326
case $posix_mkdir in
295327
'')
296-
# Create intermediate dirs using mode 755 as modified by the umask.
297-
# This is like FreeBSD 'install' as of 1997-10-28.
298-
umask=`umask`
299-
case $stripcmd.$umask in
300-
# Optimize common cases.
301-
*[2367][2367]) mkdir_umask=$umask;;
302-
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
303-
304-
*[0-7])
305-
mkdir_umask=`expr $umask + 22 \
306-
- $umask % 100 % 40 + $umask % 20 \
307-
- $umask % 10 % 4 + $umask % 2
308-
`;;
309-
*) mkdir_umask=$umask,go-w;;
310-
esac
311-
312328
# With -d, create the new directory with the user-specified mode.
313329
# Otherwise, rely on $mkdir_umask.
314330
if test -n "$dir_arg"; then
@@ -318,43 +334,49 @@ do
318334
fi
319335

320336
posix_mkdir=false
321-
case $umask in
322-
*[123567][0-7][0-7])
323-
# POSIX mkdir -p sets u+wx bits regardless of umask, which
324-
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
325-
;;
326-
*)
327-
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
328-
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
329-
330-
if (umask $mkdir_umask &&
331-
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
332-
then
333-
if test -z "$dir_arg" || {
334-
# Check for POSIX incompatibilities with -m.
335-
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
336-
# other-writable bit of parent directory when it shouldn't.
337-
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
338-
ls_ld_tmpdir=`ls -ld "$tmpdir"`
339-
case $ls_ld_tmpdir in
340-
d????-?r-*) different_mode=700;;
341-
d????-?--*) different_mode=755;;
342-
*) false;;
343-
esac &&
344-
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
345-
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
346-
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
347-
}
348-
}
349-
then posix_mkdir=:
350-
fi
351-
rmdir "$tmpdir/d" "$tmpdir"
352-
else
353-
# Remove any dirs left behind by ancient mkdir implementations.
354-
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
355-
fi
356-
trap '' 0;;
357-
esac;;
337+
# The $RANDOM variable is not portable (e.g., dash). Use it
338+
# here however when possible just to lower collision chance.
339+
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
340+
341+
trap '
342+
ret=$?
343+
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null
344+
exit $ret
345+
' 0
346+
347+
# Because "mkdir -p" follows existing symlinks and we likely work
348+
# directly in world-writeable /tmp, make sure that the '$tmpdir'
349+
# directory is successfully created first before we actually test
350+
# 'mkdir -p'.
351+
if (umask $mkdir_umask &&
352+
$mkdirprog $mkdir_mode "$tmpdir" &&
353+
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
354+
then
355+
if test -z "$dir_arg" || {
356+
# Check for POSIX incompatibilities with -m.
357+
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
358+
# other-writable bit of parent directory when it shouldn't.
359+
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
360+
test_tmpdir="$tmpdir/a"
361+
ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
362+
case $ls_ld_tmpdir in
363+
d????-?r-*) different_mode=700;;
364+
d????-?--*) different_mode=755;;
365+
*) false;;
366+
esac &&
367+
$mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
368+
ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
369+
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
370+
}
371+
}
372+
then posix_mkdir=:
373+
fi
374+
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
375+
else
376+
# Remove any dirs left behind by ancient mkdir implementations.
377+
rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
378+
fi
379+
trap '' 0;;
358380
esac
359381

360382
if
@@ -365,7 +387,7 @@ do
365387
then :
366388
else
367389

368-
# The umask is ridiculous, or mkdir does not conform to POSIX,
390+
# mkdir does not conform to POSIX,
369391
# or it failed possibly due to a race condition. Create the
370392
# directory the slow way, step by step, checking for races as we go.
371393

@@ -394,7 +416,7 @@ do
394416
prefixes=
395417
else
396418
if $posix_mkdir; then
397-
(umask=$mkdir_umask &&
419+
(umask $mkdir_umask &&
398420
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
399421
# Don't fail if two instances are running concurrently.
400422
test -d "$prefix" || exit 1
@@ -427,14 +449,25 @@ do
427449
else
428450

429451
# Make a couple of temp file names in the proper directory.
430-
dsttmp=$dstdir/_inst.$$_
431-
rmtmp=$dstdir/_rm.$$_
452+
dsttmp=${dstdirslash}_inst.$$_
453+
rmtmp=${dstdirslash}_rm.$$_
432454

433455
# Trap to clean up those temp files at exit.
434456
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
435457

436458
# Copy the file name to the temp name.
437-
(umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
459+
(umask $cp_umask &&
460+
{ test -z "$stripcmd" || {
461+
# Create $dsttmp read-write so that cp doesn't create it read-only,
462+
# which would cause strip to fail.
463+
if test -z "$doit"; then
464+
: >"$dsttmp" # No need to fork-exec 'touch'.
465+
else
466+
$doit touch "$dsttmp"
467+
fi
468+
}
469+
} &&
470+
$doit_exec $cpprog "$src" "$dsttmp") &&
438471

439472
# and set any options; do chmod last to preserve setuid bits.
440473
#
@@ -460,6 +493,13 @@ do
460493
then
461494
rm -f "$dsttmp"
462495
else
496+
# If $backupsuffix is set, and the file being installed
497+
# already exists, attempt a backup. Don't worry if it fails,
498+
# e.g., if mv doesn't support -f.
499+
if test -n "$backupsuffix" && test -f "$dst"; then
500+
$doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
501+
fi
502+
463503
# Rename the file to the real destination.
464504
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
465505

@@ -474,9 +514,9 @@ do
474514
# file should still install successfully.
475515
{
476516
test ! -f "$dst" ||
477-
$doit $rmcmd -f "$dst" 2>/dev/null ||
517+
$doit $rmcmd "$dst" 2>/dev/null ||
478518
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
479-
{ $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
519+
{ $doit $rmcmd "$rmtmp" 2>/dev/null; :; }
480520
} ||
481521
{ echo "$0: cannot unlink or rename $dst" >&2
482522
(exit 1); exit 1
@@ -493,9 +533,9 @@ do
493533
done
494534

495535
# Local variables:
496-
# eval: (add-hook 'write-file-hooks 'time-stamp)
536+
# eval: (add-hook 'before-save-hook 'time-stamp)
497537
# time-stamp-start: "scriptversion="
498538
# time-stamp-format: "%:y-%02m-%02d.%02H"
499-
# time-stamp-time-zone: "UTC"
539+
# time-stamp-time-zone: "UTC0"
500540
# time-stamp-end: "; # UTC"
501541
# End:

0 commit comments

Comments
 (0)