mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -27,59 +27,88 @@
|
||||
# foamCleanPath
|
||||
#
|
||||
# Description
|
||||
# Usage: cleanPath path [wildcard] .. [wildcard]
|
||||
# Usage: foamCleanPath path [wildcard] .. [wildcard]
|
||||
#
|
||||
# Prints its argument (which should be a ':' separated path)
|
||||
# without all
|
||||
# - duplicate elements
|
||||
# - non-accessible directories
|
||||
# - 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
|
||||
dirList="$1"
|
||||
elif [ $# -gt 1 ]; then
|
||||
dirList="$1"
|
||||
shift
|
||||
while [ 1 -le $# ] ; do
|
||||
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
|
||||
Prints its argument (which should be a ':' separated list) cleansed from
|
||||
- duplicate elements
|
||||
- non-accessible directories
|
||||
- elements whose start matches one of the wildcard(s)
|
||||
USAGE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
dirList="$1"
|
||||
shift
|
||||
|
||||
##DEBUG echo "input>$dirList<" 1>&2
|
||||
|
||||
# preserve current IFS and split on whitespace
|
||||
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
|
||||
|
||||
#- non existing
|
||||
if [ ! -e "$dir" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
#- duplicate
|
||||
dirListWithout=`echo ":${newDirList}:" | sed -e "s@:${dir}:@::@"`
|
||||
if [ "$dirListWithout" != ":${newDirList}:" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
newDirList="$newDirList:$dir"
|
||||
wildcard=$1
|
||||
shift
|
||||
##DEBUG echo "remove>$wildcard<" 1>&2
|
||||
dirList=`echo "$dirList" | sed -e "s@${wildcard}[^:]*:@@g"`
|
||||
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"
|
||||
|
||||
# Remove leading or trailing colons
|
||||
echo "$newDirList" | sed -e 's@^:@@' -e 's@:$@@'
|
||||
##DEBUG echo "output>$dirList<" 1>&2
|
||||
echo "$dirList"
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
14
etc/bashrc
14
etc/bashrc
@ -175,11 +175,12 @@ wildCards="$FOAM_INST_DIR $HOME/$WM_PROJECT/$USER"
|
||||
cleanPath=`$cleanProg "$PATH" "$wildCards"` && PATH="$cleanPath"
|
||||
|
||||
#- 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
|
||||
export MANPATH=`$cleanProg "$MANPATH" "$wildCards"`
|
||||
cleanPath=`$cleanProg "$MANPATH" "$wildCards"` && MANPATH="$cleanPath"
|
||||
|
||||
export PATH LD_LIBRARY_PATH MANPATH
|
||||
|
||||
# Source project setup files
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@ -208,14 +209,17 @@ SOURCE $WM_PROJECT_DIR/etc/apps/cint/bashrc
|
||||
cleanPath=`$cleanProg "$PATH"` && PATH="$cleanPath"
|
||||
|
||||
#- Clean LD_LIBRARY_PATH
|
||||
export LD_LIBRARY_PATH=`$cleanProg "$LD_LIBRARY_PATH"`
|
||||
cleanPath=`$cleanProg "$LD_LIBRARY_PATH"` && LD_LIBRARY_PATH="$cleanPath"
|
||||
|
||||
#- Clean MANPATH
|
||||
export MANPATH=`$cleanProg "$MANPATH"`
|
||||
cleanPath=`$cleanProg "$MANPATH"` && MANPATH="$cleanPath"
|
||||
|
||||
export PATH LD_LIBRARY_PATH MANPATH
|
||||
|
||||
#- Clean LD_PRELOAD
|
||||
if [ "$LD_PRELOAD" != "" ]; then
|
||||
export LD_PRELOAD=`$cleanProg "$LD_PRELOAD"`
|
||||
cleanPath=`$cleanProg "$LD_PRELOAD"` && LD_PRELOAD="$cleanPath"
|
||||
export LD_PRELOAD
|
||||
fi
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user