FIX: foamCleanPath wasn't working properly with etc/bashrc.

The call to foamCleanPath from etc/{bashrc,cshrc} passes all the wildcards
together as a single argument - causing nothing to be cleaned.  Now split
the args on whitespace. Also added more IFS hacking to reduce forking.
This commit is contained in:
Mark Olesen
2008-05-21 10:07:28 +02:00
parent 71119dd6eb
commit e34c1c75f8
2 changed files with 73 additions and 40 deletions

View File

@ -27,59 +27,88 @@
# foamCleanPath # foamCleanPath
# #
# Description # Description
# Usage: cleanPath path [wildcard] .. [wildcard] # Usage: foamCleanPath path [wildcard] .. [wildcard]
# #
# Prints its argument (which should be a ':' separated path) # Prints its argument (which should be a ':' separated path)
# without all # without all
# - duplicate elements # - duplicate elements
# - non-accessible directories # - non-accessible directories
# - elements whose start matches a wildcard # - elements whose start matches a wildcard
#
# Note:
# - this routine will fail when directories have embedded spaces
# - false matches possible if a wildcard contains '.' (sed regex)
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
if [ "$#" -lt 1 -o "$1" = "-h" -o "$1" = "-help" ]
then
cat <<USAGE 1>&2
Usage: ${0##*/} path [wildcard] .. [wildcard]
if [ $# -eq 1 ]; then Prints its argument (which should be a ':' separated list) cleansed from
dirList="$1" - duplicate elements
elif [ $# -gt 1 ]; then - non-accessible directories
dirList="$1" - elements whose start matches one of the wildcard(s)
shift USAGE
while [ 1 -le $# ] ; do exit 1
wildCard=$1
shift
dirList=`echo "$dirList" | sed -e "s@${wildCard}[^:]*:@@g"`
done
else
echo "Usage: $0 path [wildcard]" 1>&2
echo "" 1>&2
echo "Prints argument path with all entries matching " 1>&2
echo "the wildcard removed." 1>&2
exit 1
fi fi
dirList="$1"
shift
##DEBUG echo "input>$dirList<" 1>&2
# preserve current IFS and split on whitespace
oldIFS="$IFS" oldIFS="$IFS"
IFS=':' IFS=' '
newDirList='' # "wildcard1 ... wildcardN" may have been passed as a single parameter
set -- $*
for dir in $dirList # strip out wildcards via sed
while [ "$#" -ge 1 ]
do do
wildcard=$1
#- non existing shift
if [ ! -e "$dir" ]; then ##DEBUG echo "remove>$wildcard<" 1>&2
continue dirList=`echo "$dirList" | sed -e "s@${wildcard}[^:]*:@@g"`
fi
#- duplicate
dirListWithout=`echo ":${newDirList}:" | sed -e "s@:${dir}:@::@"`
if [ "$dirListWithout" != ":${newDirList}:" ]; then
continue
fi
newDirList="$newDirList:$dir"
done done
# split on ':' (and on space as well to avoid any surprises)
IFS=': '
set -- $dirList
##DEBUG echo "intermediate>$dirList<" 1>&2
# rebuild the list from scratch
unset dirList
for dir
do
##DEBUG echo "check>$dir<" 1>&2
#- dirs must exist
if [ -e "$dir" ]
then
#- no duplicate dirs
duplicate=`echo " $dirList " | sed -ne "s@ $dir @DUP@p"`
if [ ! "$duplicate" ]
then
dirList="$dirList $dir"
fi
fi
done
# parse on whitespace
IFS=' '
set -- $dirList
# join on ':'
IFS=':'
dirList="$*"
# restore IFS
IFS="$oldIFS" IFS="$oldIFS"
# Remove leading or trailing colons ##DEBUG echo "output>$dirList<" 1>&2
echo "$newDirList" | sed -e 's@^:@@' -e 's@:$@@' echo "$dirList"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------

View File

@ -175,11 +175,12 @@ wildCards="$FOAM_INST_DIR $HOME/$WM_PROJECT/$USER"
cleanPath=`$cleanProg "$PATH" "$wildCards"` && PATH="$cleanPath" cleanPath=`$cleanProg "$PATH" "$wildCards"` && PATH="$cleanPath"
#- Clean LD_LIBRARY_PATH #- Clean LD_LIBRARY_PATH
export LD_LIBRARY_PATH=`$cleanProg "$LD_LIBRARY_PATH" "$wildCards"` cleanPath=`$cleanProg "$LD_LIBRARY_PATH" "$wildCards"` && LD_LIBRARY_PATH="$cleanPath"
#- Clean MANPATH #- Clean MANPATH
export MANPATH=`$cleanProg "$MANPATH" "$wildCards"` cleanPath=`$cleanProg "$MANPATH" "$wildCards"` && MANPATH="$cleanPath"
export PATH LD_LIBRARY_PATH MANPATH
# Source project setup files # Source project setup files
# ~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -208,14 +209,17 @@ SOURCE $WM_PROJECT_DIR/etc/apps/cint/bashrc
cleanPath=`$cleanProg "$PATH"` && PATH="$cleanPath" cleanPath=`$cleanProg "$PATH"` && PATH="$cleanPath"
#- Clean LD_LIBRARY_PATH #- Clean LD_LIBRARY_PATH
export LD_LIBRARY_PATH=`$cleanProg "$LD_LIBRARY_PATH"` cleanPath=`$cleanProg "$LD_LIBRARY_PATH"` && LD_LIBRARY_PATH="$cleanPath"
#- Clean MANPATH #- Clean MANPATH
export MANPATH=`$cleanProg "$MANPATH"` cleanPath=`$cleanProg "$MANPATH"` && MANPATH="$cleanPath"
export PATH LD_LIBRARY_PATH MANPATH
#- Clean LD_PRELOAD #- Clean LD_PRELOAD
if [ "$LD_PRELOAD" != "" ]; then if [ "$LD_PRELOAD" != "" ]; then
export LD_PRELOAD=`$cleanProg "$LD_PRELOAD"` cleanPath=`$cleanProg "$LD_PRELOAD"` && LD_PRELOAD="$cleanPath"
export LD_PRELOAD
fi fi