xbps-src: replace basename(1) with ${var##*/}.

Reduce number of fork+exec due to using a subshell to execute basename(1).
This commit is contained in:
Juan RP 2015-09-11 07:55:40 +02:00
parent ea9c012c04
commit bcdacb66a0
20 changed files with 28 additions and 23 deletions

View File

@ -147,9 +147,9 @@ _vinstall() {
fi fi
if [ -z "$targetfile" ]; then if [ -z "$targetfile" ]; then
install -Dm${mode} ${file} "${_destdir}/${targetdir}/$(basename ${file})" install -Dm${mode} ${file} "${_destdir}/${targetdir}/${file##*/}"
else else
install -Dm${mode} ${file} "${_destdir}/${targetdir}/$(basename ${targetfile})" install -Dm${mode} ${file} "${_destdir}/${targetdir}/${targetfile##*/}"
fi fi
} }

View File

@ -55,7 +55,7 @@ try_mirrors() {
local curfile="$1" distfile="$2" dfcount="$3" subdir="$4" f="$5" local curfile="$1" distfile="$2" dfcount="$3" subdir="$4" f="$5"
local filesum cksum basefile mirror path scheme local filesum cksum basefile mirror path scheme
[ -z "$XBPS_DISTFILES_MIRROR" ] && return [ -z "$XBPS_DISTFILES_MIRROR" ] && return
basefile="$(basename $f)" basefile="${f##*/}"
cksum=$(get_cksum $curfile $dfcount) cksum=$(get_cksum $curfile $dfcount)
for mirror in $XBPS_DISTFILES_MIRROR; do for mirror in $XBPS_DISTFILES_MIRROR; do
scheme="file" scheme="file"

View File

@ -4,7 +4,8 @@ _process_patch() {
local _args= _patch= i=$1 local _args= _patch= i=$1
_args="-Np0" _args="-Np0"
_patch=$(basename $i) _patch=${i##*/}
if [ -f $PATCHESDIR/${_patch}.args ]; then if [ -f $PATCHESDIR/${_patch}.args ]; then
_args=$(cat $PATCHESDIR/${_patch}.args) _args=$(cat $PATCHESDIR/${_patch}.args)
elif [ -n "$patch_args" ]; then elif [ -n "$patch_args" ]; then

View File

@ -32,7 +32,7 @@ hook() {
if [ -h ${PKGDESTDIR}/"$j" ]; then if [ -h ${PKGDESTDIR}/"$j" ]; then
dirat=$(dirname "$j") dirat=$(dirname "$j")
lnkat=$(readlink ${PKGDESTDIR}/"$j") lnkat=$(readlink ${PKGDESTDIR}/"$j")
newlnk=$(basename "$j") newlnk="${j##*/}"
rm -f ${PKGDESTDIR}/"$j" rm -f ${PKGDESTDIR}/"$j"
cd ${PKGDESTDIR}/"$dirat" cd ${PKGDESTDIR}/"$dirat"
ln -s "${lnkat}".gz "${newlnk}".gz ln -s "${lnkat}".gz "${newlnk}".gz

View File

@ -205,7 +205,7 @@ _EOF
if [ -d ${PKGDESTDIR}/usr/share/gconf/schemas ]; then if [ -d ${PKGDESTDIR}/usr/share/gconf/schemas ]; then
_add_trigger gconf-schemas _add_trigger gconf-schemas
for f in ${PKGDESTDIR}/usr/share/gconf/schemas/*.schemas; do for f in ${PKGDESTDIR}/usr/share/gconf/schemas/*.schemas; do
_schemas="${_schemas} $(basename $f)" _schemas="${_schemas} ${f##*/}"
done done
echo "export gconf_schemas=\"${_schemas}\"" >> $tmpf echo "export gconf_schemas=\"${_schemas}\"" >> $tmpf
fi fi

View File

@ -8,7 +8,7 @@ make_debug() {
[ -n "$nodebug" ] && return 0 [ -n "$nodebug" ] && return 0
dname=$(echo "$(dirname $1)"|sed -e "s|${PKGDESTDIR}||g") dname=$(echo "$(dirname $1)"|sed -e "s|${PKGDESTDIR}||g")
fname="$(basename $1)" fname="${1##*/}"
dbgfile="${dname}/${fname}" dbgfile="${dname}/${fname}"
mkdir -p "${PKGDESTDIR}/usr/lib/debug/${dname}" mkdir -p "${PKGDESTDIR}/usr/lib/debug/${dname}"
@ -27,7 +27,7 @@ attach_debug() {
[ -n "$nodebug" ] && return 0 [ -n "$nodebug" ] && return 0
dname=$(echo "$(dirname $1)"|sed -e "s|${PKGDESTDIR}||g") dname=$(echo "$(dirname $1)"|sed -e "s|${PKGDESTDIR}||g")
fname="$(basename $1)" fname="${1##*/}"
dbgfile="${dname}/${fname}" dbgfile="${dname}/${fname}"
$OBJCOPY --add-gnu-debuglink="${PKGDESTDIR}/usr/lib/debug/${dbgfile}" "$1" $OBJCOPY --add-gnu-debuglink="${PKGDESTDIR}/usr/lib/debug/${dbgfile}" "$1"
@ -69,7 +69,7 @@ hook() {
continue continue
fi fi
fname=$(basename "$f") fname=${f##*/}
for x in ${nostrip_files}; do for x in ${nostrip_files}; do
if [ "$x" = "$fname" ]; then if [ "$x" = "$fname" ]; then
found=1 found=1

View File

@ -79,8 +79,12 @@ _EOF
} }
install_wrappers() { install_wrappers() {
local fname
for f in ${XBPS_COMMONDIR}/wrappers/*.sh; do for f in ${XBPS_COMMONDIR}/wrappers/*.sh; do
install -m0755 ${f} ${XBPS_WRAPPERDIR}/$(basename ${f%.sh}) fname=${f##*/}
fname=${fname%.sh}
install -m0755 ${f} ${XBPS_WRAPPERDIR}/${fname}
done done
} }

View File

@ -13,7 +13,7 @@ collect_sonames() {
# real pkg # real pkg
find ${_destdir} -type f -name "*.so*" | while read f; do find ${_destdir} -type f -name "*.so*" | while read f; do
_fname=$(basename "$f") _fname="${f##*/}"
case "$(file -bi "$f")" in case "$(file -bi "$f")" in
application/x-sharedlib*) application/x-sharedlib*)
# shared library # shared library

View File

@ -10,7 +10,7 @@
# $5 - internal [OPTIONAL] # $5 - internal [OPTIONAL]
if [ $# -lt 3 -o $# -gt 5 ]; then if [ $# -lt 3 -o $# -gt 5 ]; then
echo "$(basename $0): invalid number of arguments: pkgname targetpkg target [cross-target]" echo "${0##*/}: invalid number of arguments: pkgname targetpkg target [cross-target]"
exit 1 exit 1
fi fi

View File

@ -7,7 +7,7 @@
# $2 - cross target [OPTIONAL] # $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]" echo "${0##*/}: invalid number of arguments: pkgname [cross-target]"
exit 1 exit 1
fi fi

View File

@ -7,7 +7,7 @@
# $2 - cross target [OPTIONAL] # $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]" echo "${0##*/}: invalid number of arguments: pkgname [cross-target]"
exit 1 exit 1
fi fi

View File

@ -7,7 +7,7 @@
# $2 - cross target [OPTIONAL] # $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]" echo "${0##*/}: invalid number of arguments: pkgname [cross-target]"
exit 1 exit 1
fi fi

View File

@ -7,7 +7,7 @@
# $2 - cross target [OPTIONAL] # $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]" echo "${0##*/}: invalid number of arguments: pkgname [cross-target]"
exit 1 exit 1
fi fi

View File

@ -7,7 +7,7 @@
# $2 - cross target [OPTIONAL] # $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]" echo "${0##*/}: invalid number of arguments: pkgname [cross-target]"
exit 1 exit 1
fi fi

View File

@ -8,7 +8,7 @@
# $3 - cross-target [OPTIONAL] # $3 - cross-target [OPTIONAL]
if [ $# -lt 2 -o $# -gt 3 ]; then if [ $# -lt 2 -o $# -gt 3 ]; then
echo "$(basename $0): invalid number of arguments: pkgname repository [cross-target]" echo "${0##*/}: invalid number of arguments: pkgname repository [cross-target]"
exit 1 exit 1
fi fi

View File

@ -7,7 +7,7 @@
# $2 - cross target [OPTIONAL] # $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]" echo "${0##*/}: invalid number of arguments: pkgname [cross-target]"
exit 1 exit 1
fi fi

View File

@ -1,7 +1,7 @@
# vim: set ts=4 sw=4 et: # vim: set ts=4 sw=4 et:
bulk_getlink() { bulk_getlink() {
local p="$(basename $1)" local p="${1##*/}"
local target="$(readlink $XBPS_SRCPKGDIR/$p)" local target="$(readlink $XBPS_SRCPKGDIR/$p)"
if [ $? -eq 0 -a -n "$target" ]; then if [ $? -eq 0 -a -n "$target" ]; then

View File

@ -182,7 +182,7 @@ run_pkg_hooks() {
eval unset -f hook eval unset -f hook
for f in ${XBPS_COMMONDIR}/hooks/${phase}/*.sh; do for f in ${XBPS_COMMONDIR}/hooks/${phase}/*.sh; do
[ ! -r $f ] && continue [ ! -r $f ] && continue
hookn=$(basename $f) hookn=${f##*/}
hookn=${hookn%.sh} hookn=${hookn%.sh}
. $f . $f
run_func hook "$phase hook: $hookn" ${phase}_${hookn} run_func hook "$phase hook: $hookn" ${phase}_${hookn}

View File

@ -75,7 +75,7 @@ purge_distfiles() {
hashes=($XBPS_SRCDISTDIR/by_sha256/*) hashes=($XBPS_SRCDISTDIR/by_sha256/*)
readonly HASHLEN=64 readonly HASHLEN=64
for file in ${hashes[@]}; do for file in ${hashes[@]}; do
hash_distfile=$(basename "$file") hash_distfile=${file##*/}
hash=${hash_distfile:0:$HASHLEN} hash=${hash_distfile:0:$HASHLEN}
[ -n "${my_hashes[$hash]}" ] && continue [ -n "${my_hashes[$hash]}" ] && continue
inode=$(stat "$file" --printf "%i") inode=$(stat "$file" --printf "%i")

View File

@ -6,7 +6,7 @@ update_hash_cache() {
mkdir -p "$cache" mkdir -p "$cache"
find "$XBPS_SRCDISTDIR" -type f | grep -v by_sha256 | while read -r distfile; do find "$XBPS_SRCDISTDIR" -type f | grep -v by_sha256 | while read -r distfile; do
cksum=$(cat "$distfile" | sha256sum | cut -d " " -f 1) cksum=$(cat "$distfile" | sha256sum | cut -d " " -f 1)
curfile="$(basename ${distfile})" curfile="${distfile##*/}"
ln -vf "$distfile" "${cache}/${cksum}_${curfile}" ln -vf "$distfile" "${cache}/${cksum}_${curfile}"
done done
} }