[Lunar-commits] r18697 - lunar/trunk/var/lib/lunar/functions
Auke Kok
sofar at lunar-linux.org
Sun Feb 12 06:33:41 UTC 2006
Author: sofar
Date: 2006-02-12 06:33:36 +0000 (Sun, 12 Feb 2006)
New Revision: 18697
Modified:
lunar/trunk/var/lib/lunar/functions/aliases.lunar
lunar/trunk/var/lib/lunar/functions/depends.lunar
Log:
Some more optimizations in the most time-consuming parts.
Modified: lunar/trunk/var/lib/lunar/functions/aliases.lunar
===================================================================
--- lunar/trunk/var/lib/lunar/functions/aliases.lunar 2006-02-12 05:48:09 UTC (rev 18696)
+++ lunar/trunk/var/lib/lunar/functions/aliases.lunar 2006-02-12 06:33:36 UTC (rev 18697)
@@ -13,88 +13,92 @@
# and add it to the dependency chain if needed
unalias() {
local TARGET TARGETS TARGETBYNUM N CHOICE
+ # quick exit code
+ if [ "${1:0:1}" != "%" ] ; then
+ echo $1
+ return
+ fi
+
+ debug_msg "unalias($@)"
# try to figure out where the aliases file is:
- if [ -z "$ALIASES" -o ! -f "$ALIASES" ]; then
+ if [[ -z "$ALIASES" ]] || [[ ! -f "$ALIASES" ]]; then
if [ -f "$MOONBASE/aliases" ] ; then
ALIASES="$MOONBASE/aliases"
else
ALIASES="/var/lib/lunar/aliases"
fi
fi
- if [ "${1:0:1}" == "%" ] ; then
- debug_msg "unalias($@)"
- TARGETS=$(grep "^$1:" $ALIASES | cut -d: -f2-)
- # dumb algorithm: pick the first installed one
+
+ TARGETS=$(awk -F: -v mod=$1 '{if ($1==mod){print $2}}' $ALIASES)
+ # dumb algorithm: pick the first installed one
+ for TARGET in $TARGETS ; do
+ if module_installed $TARGET ; then
+ debug_msg "unaliased \"$1\"->\"$TARGET\""
+ echo $TARGET
+ return
+ fi
+ done
+ # shortcut out: in the satisfy_depends stage we should NOT ask this again
+ if [[ -z "$DEPS_ONLY" ]] ; then
+ # first we check if this dependency is already existant in the exact
+ # way: does this MODULE depends on TARGET already ?
for TARGET in $TARGETS ; do
- if $(module_installed $TARGET) ; then
+ if in_depends $MODULE $TARGET ; then
debug_msg "unaliased \"$1\"->\"$TARGET\""
echo $TARGET
return
fi
done
- # shortcut out: in the satisfy_depends stage we should NOT ask this again
- if [ -z "$DEPS_ONLY" ] ; then
- # first we check if this dependency is already existant in the exact
- # way: does this MODULE depends on TARGET already ?
- for TARGET in $TARGETS ; do
- if in_depends $MODULE $TARGET ; then
- debug_msg "unaliased \"$1\"->\"$TARGET\""
- echo $TARGET
- return
- fi
- done
- # not so... other possibility is that something else already depends
- # on TARGET?
- for TARGET in $TARGETS ; do
- if is_depends $TARGET ; then
- debug_msg "unaliased \"$1\"->\"$TARGET\""
- echo $TARGET
- return
- fi
- done
- # also not so. our last attempt is for a DISABLED dependency, but
- # we can only use this method for OPTIONAL dependencies
- for TARGET in $TARGETS ; do
- # there's no function for this yet
- if grep -q ":$TARGET:off:" $DEPENDS_STATUS ; then
- debug_msg "unaliased \"$1\"->\"$TARGET\""
- echo $TARGET
- return
- fi
- done
- fi
-
- # shortcut out when explicitly instructed so
- if [ -n "$NEVER_ASK" ] ; then
- echo $1
- return
- fi
-
- # propose one and let the user pick it from a list:
- debug_msg "unalias: starting selection loop"
- error_message "${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} depends on ${DEFAULT_COLOR}${QUERY_COLOR}\"${1:1}\"${DEFAULT_COLOR}${MESSAGE_COLOR} which is an alias${DEFAULT_COLOR}"
- while true ; do
- error_message "${MESSAGE_COLOR}Please select a substitute ! Enter the number or the name of the module${DEFAULT_COLOR}"
- ((N=0))
- for TARGET in $TARGETS ; do
- ((N++))
- TARGETBYNUM[$N]=$TARGET
- error_message " ${QUERY_COLOR}$N${MESSAGE_COLOR} - ${DEFAULT_COLOR}${MODULE_COLOR}$TARGET${DEFAULT_COLOR}"
- done
- read CHOICE
- # test directly first
- if echo $TARGETS | grep -qw "$CHOICE" ; then
+ # not so... other possibility is that something else already depends
+ # on TARGET?
+ for TARGET in $TARGETS ; do
+ if is_depends $TARGET ; then
+ debug_msg "unaliased \"$1\"->\"$TARGET\""
echo $TARGET
return
- # then the number
- elif [ -n "$CHOICE" -a -n "${TARGETBYNUM[$CHOICE]}" ] ; then
- echo ${TARGETBYNUM[$CHOICE]}
+ fi
+ done
+ # also not so. our last attempt is for a DISABLED dependency, but
+ # we can only use this method for OPTIONAL dependencies
+ for TARGET in $TARGETS ; do
+ # there's no function for this yet
+ if grep -q ":$TARGET:off:" $DEPENDS_STATUS ; then
+ debug_msg "unaliased \"$1\"->\"$TARGET\""
+ echo $TARGET
return
fi
- error_message "${MESSAGE_COLOR}Sorry, I can't do anything with \"${DEFAULT_COLOR}${QUERY_COLOR}$CHOICE${DEFAULT_COLOR}${MESSAGE_COLOR}\", please try again${DEFAULT_COLOR}"
done
- else
+ fi
+
+ # shortcut out when explicitly instructed so
+ if [[ -n "$NEVER_ASK" ]] ; then
echo $1
return
fi
+
+ # propose one and let the user pick it from a list:
+ debug_msg "unalias: starting selection loop"
+ error_message "${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} depends on ${DEFAULT_COLOR}${QUERY_COLOR}\"${1:1}\"${DEFAULT_COLOR}${MESSAGE_COLOR} which is an alias${DEFAULT_COLOR}"
+ while true ; do
+ error_message "${MESSAGE_COLOR}Please select a substitute ! Enter the number or the name of the module${DEFAULT_COLOR}"
+ ((N=0))
+ for TARGET in $TARGETS ; do
+ ((N++))
+ TARGETBYNUM[$N]=$TARGET
+ error_message " ${QUERY_COLOR}$N${MESSAGE_COLOR} - ${DEFAULT_COLOR}${MODULE_COLOR}$TARGET${DEFAULT_COLOR}"
+ done
+ read CHOICE
+ # test directly first
+ if $(echo $TARGETS | grep -qw "$CHOICE") ; then
+ echo $TARGET
+ return
+ # then the number
+ elif [[ -n "$CHOICE" ]] && [[ -n "${TARGETBYNUM[$CHOICE]}" ]] ; then
+ echo ${TARGETBYNUM[$CHOICE]}
+ return
+ fi
+ error_message "${MESSAGE_COLOR}Sorry, I can't do anything with \"${DEFAULT_COLOR}${QUERY_COLOR}$CHOICE${DEFAULT_COLOR}${MESSAGE_COLOR}\", please try again${DEFAULT_COLOR}"
+ done
}
+
+
Modified: lunar/trunk/var/lib/lunar/functions/depends.lunar
===================================================================
--- lunar/trunk/var/lib/lunar/functions/depends.lunar 2006-02-12 05:48:09 UTC (rev 18696)
+++ lunar/trunk/var/lib/lunar/functions/depends.lunar 2006-02-12 06:33:36 UTC (rev 18697)
@@ -30,15 +30,13 @@
find_depends_intern() {
local DEP STATE LINE
- grep "^$1:" $DEPENDS_CACHE | while read LINE ; do
- DEP=$(echo $LINE | cut -d: -f2)
+ awk -F: -v mod=$1 '{if ($1==mod){print $2,$3}}' $DEPENDS_CACHE | while read DEP STATE ; do
DEP=$(unalias $DEP)
# this is our shortcut out:
if ! grep -qx "$DEP" $TMP_FDEPS ; then
- debug_msg "$DEP"
+ debug_msg "$DEP"
echo "$DEP" >> $TMP_FDEPS
- STATE=$(echo $LINE | cut -d: -f3)
- if [ "$STATE" == "required" ] ; then
+ if [[ "$STATE" == "required" ]] ; then
echo $DEP
find_depends_intern $DEP
elif module_installed $DEP ; then
@@ -71,7 +69,7 @@
# tsort the existing dep relations in all of moonbase
TMP_TSRT=$(temp_create "dependency.sort")
- cat $DEPENDS_CACHE | cut -d: -f1,2 --output-delimiter=" " | while read A B ; do
+ awk -F: '{print $1,$2}' $DEPENDS_CACHE | while read A B ; do
B=$(MODULE=$A NEVER_ASK=1 DEPS_ONLY= unalias $B)
echo "$A $B" >> $TMP_TSRT
done
@@ -145,7 +143,7 @@
fi
echo "$1:$2:$3:$4:$5:$6" >> $DEPENDS_STATUS &&
- cat $DEPENDS_STATUS > $DEPENDS_STATUS_BACKUP &&
+ cp $DEPENDS_STATUS $DEPENDS_STATUS_BACKUP &&
unlock_file $DEPENDS_STATUS &&
unlock_file $DEPENDS_STATUS_BACKUP
fi
More information about the Lunar-commits
mailing list