makeWrapper: Only wrap normal executable files

`makeWrapper` and `wrapProgram` are being invoked on all kinds of
wacky things (usually with the help of bash globs or other machine
assistance).

So far, I have come across `wrapProgram` being invoked on a directory,
as well as on the empty string.

As far as I can tell, it's only valid to invoke these utilities on a
normal (non-directory, non-device) executable file.  This commit
enforces that precondition.
This commit is contained in:
Taahir Ahmed 2017-07-30 13:42:20 -05:00
parent ba68231273
commit e1d46c0c4d

View File

@ -1,3 +1,12 @@
# Assert that FILE exists and is executable
#
# assertExecutable FILE
assertExecutable() {
local file="$1"
[[ -f "${file}" && -x "${file}" ]] || \
die "Cannot wrap ${file} because it is not an executable file"
}
# construct an executable file that wraps the actual executable # construct an executable file that wraps the actual executable
# makeWrapper EXECUTABLE ARGS # makeWrapper EXECUTABLE ARGS
@ -24,6 +33,8 @@ makeWrapper() {
local params varName value command separator n fileNames local params varName value command separator n fileNames
local argv0 flagsBefore flags local argv0 flagsBefore flags
assertExecutable "${file}"
mkdir -p "$(dirname "$wrapper")" mkdir -p "$(dirname "$wrapper")"
echo "#! $SHELL -e" > "$wrapper" echo "#! $SHELL -e" > "$wrapper"
@ -131,6 +142,9 @@ filterExisting() {
wrapProgram() { wrapProgram() {
local prog="$1" local prog="$1"
local hidden local hidden
assertExecutable "${prog}"
hidden="$(dirname "$prog")/.$(basename "$prog")"-wrapped hidden="$(dirname "$prog")/.$(basename "$prog")"-wrapped
while [ -e "$hidden" ]; do while [ -e "$hidden" ]; do
hidden="${hidden}_" hidden="${hidden}_"