[Lunar-commits] r21965 - lunar/trunk/var/lib/lunar/functions

Auke Kok sofar at lunar-linux.org
Fri Oct 27 19:26:39 CEST 2006


Author: sofar
Date: 2006-10-27 19:26:39 +0200 (Fri, 27 Oct 2006)
New Revision: 21965

Modified:
   lunar/trunk/var/lib/lunar/functions/depends.lunar
Log:
[FIX] make sure alias doesn't loop

find_depends was using a stdin | read loop which breaks anything
in that context that might read from user input. We take a small
performance hit by not using the smart awk call but instead split
up the STATE lookup which is not executed for each round. All in all
this should perform the same as the old code.

some small whitespace fixes here too.


Modified: lunar/trunk/var/lib/lunar/functions/depends.lunar
===================================================================
--- lunar/trunk/var/lib/lunar/functions/depends.lunar	2006-10-27 12:09:55 UTC (rev 21964)
+++ lunar/trunk/var/lib/lunar/functions/depends.lunar	2006-10-27 17:26:39 UTC (rev 21965)
@@ -29,19 +29,19 @@
   debug_msg "find_depends ($@)"
 
   find_depends_intern() {
-    local DEP STATE LINE
-    awk -F: -v mod=$1 '{if ($1==mod){print $2,$3}}' $DEPENDS_CACHE | while read DEP STATE ; do
-      DEP=$(unalias $DEP)
+    local DEP LINE
+    for DEP in $(awk -F: -v mod=$1 '{if ($1==mod){print $2}}' $DEPENDS_CACHE) ; do
+      DEP=$(unalias "$DEP")
       # this is our shortcut out:
       if ! grep -qx "$DEP" $TMP_FDEPS ; then
         debug_msg "$DEP"
         echo "$DEP" >> $TMP_FDEPS
-        if [[ "$STATE" == "required" ]] ; then
-          echo $DEP
-          find_depends_intern $DEP
-        elif module_installed $DEP ; then
-          echo $DEP
-          find_depends_intern $DEP
+        if [[ "$(grep "^$:1$DEP:" $DEPENDS_CACHE | cut -d: -f3)" == "required" ]] ; then
+          echo "$DEP"
+          find_depends_intern "$DEP"
+        elif module_installed "$DEP" ; then
+          echo "$DEP"
+          find_depends_intern "$DEP"
         fi
       fi
     done
@@ -105,14 +105,14 @@
   # Was $2 presented as a dependency for module $1
   return $(grep -q "^$1:$2:on:" $DEPENDS_STATUS)
 }
-                                                                                
-                                                                                
+
+
 remove_depends() {
   debug_msg "remove_depends ($@)"
   lock_file $DEPENDS_STATUS_BACKUP &&
   lock_file $DEPENDS_STATUS        ||
   return 1
-                                                                                
+
   if [ -n "$2" ] ; then
     if grep -q "^$1:$2:" $DEPENDS_STATUS ; then
       grep -v "^$1:$2:" $DEPENDS_STATUS_BACKUP > $DEPENDS_STATUS
@@ -125,12 +125,12 @@
   fi
 
   cp $DEPENDS_STATUS $DEPENDS_STATUS_BACKUP
-                                                                                
+
   unlock_file $DEPENDS_STATUS &&
   unlock_file $DEPENDS_STATUS_BACKUP
 }
-                                                                                
 
+
 add_depends() {
   debug_msg "add_depends ($@)"
   if ! grep -q "^$1:$2:$3:$4:$5:$6$" $DEPENDS_STATUS ; then
@@ -141,15 +141,15 @@
 	else
       verbose_msg "adding \"$4\" depends for \"$1\" on \"$2\" ($3)"
 	fi
-                                                                                
+
     echo "$1:$2:$3:$4:$5:$6" >> $DEPENDS_STATUS            &&
     cp $DEPENDS_STATUS $DEPENDS_STATUS_BACKUP              &&
     unlock_file $DEPENDS_STATUS                            &&
     unlock_file $DEPENDS_STATUS_BACKUP
   fi
 }
-                                                                                
-     
+
+
 run_depends() {
   debug_msg "run_depends ($@)"
   # local definitions of depends and optional_depends!
@@ -178,7 +178,7 @@
       fi
     fi
   }
-                                                                                
+
   optional_depends()  {
   debug_msg "  optional_depends ($@)"
     local DEP DEFAULT DEPMOD_AVAIL
@@ -189,7 +189,7 @@
 
     DEP=$(unalias $1)
     if ! grep -q "^$MODULE:$DEP:" $DEPENDS_STATUS ; then
-                                                                               
+
       if module_exiled $DEP ; then
         verbose_msg "\"$MODULE\" optionally depends on exiled module \"$DEP\""
         add_depends "$MODULE" "$DEP" "off" "optional" "$2" "$3"
@@ -221,7 +221,7 @@
       fi
     fi
   }
-                                                                                
+
   grep -q "^"$MODULE"\$" $TEMP_PREPAREDDEPS 2>/dev/null && return 0
   if has_module_file $MODULE DEPENDS ; then
     if [ -n "$SINGLE_MODULE" ] ; then
@@ -267,14 +267,14 @@
       fi
     fi
   done
-  
+
   # then parse $OPTS
   while read LINE; do
     DEP_MODULE=$(echo $LINE | cut -d: -f2)
     DEP_STATUS=$(echo $LINE | cut -d: -f3)
         DEP_ON=$(echo $LINE | cut -d: -f5)
        DEP_OFF=$(echo $LINE | cut -d: -f6)
-                                                                                
+
     if [ -n "$FIX" ] ; then
       if DEP_STATUS="on" ; then
         lin $FIX $DEP_MODULE
@@ -292,7 +292,7 @@
       OPTS="$OPTS $DEP_ON"
     fi
   done < $TMP_FILE
-                                            
+
   temp_destroy $TMP_FILE
 }
 



More information about the Lunar-commits mailing list