Fix find_binary always succeeding

find_binary inside dracut-functions always succeeds. Independent of
whether the file actually exists or not.

This patch fixes this.

And since we're using the function not only to find binaries at little
enhancement there shouldn't be that bad either.

--
dracut-functions |   21 ++++++++++++++++-----
  1 files changed, 16 insertions(+), 5 deletions(-)
master
Seewer Philippe 2009-02-27 14:28:40 +01:00 committed by Harald Hoyer
parent acf324172d
commit 9b88534374
1 changed files with 16 additions and 5 deletions

View File

@ -53,15 +53,26 @@ inst_library() {
fi
}
find_binary() {
local binpath="/bin /sbin /usr/bin /usr/sbin" p
[[ ${1##*/} = $1 ]] || { echo $1; return 0; }
find_file() {
local binpath="/bin /sbin /usr/bin /usr/sbin" p

#Full path or not?
if [[ ${1##*/} != $1 ]] ; then
if [[ -e $1 ]] ; then
echo $1;
return 0;
fi
return 1;
fi
#Search in path
for p in $binpath; do
[[ -x $p/$1 ]] && { echo "$p/$1"; return 0; }
[[ -x $p/$1 ]] && { echo "$p/$1"; return 0; }
[[ -e $p/$1 ]] && { echo "$p/$1"; return 0; }
done
return 1
}


# Same as above.
# If the file is a binary executable, install all its
# shared library dependencies, if any.
@ -134,7 +145,7 @@ inst() {
echo "usage: inst <file> <root> [<destination file>]"
return 1
fi
local src=$(find_binary "$1") || {
local src=$(find_file "$1") || {
echo "Cannot find requested file $1. Exiting."
exit 1
}