Hi All,

I mentioned a couple of days ago that I was looking into dependencies. I have now got some code ready for testing, which I include below as a patch file. (Please note that this is taken against the 0.9.2test1 version without the patch I suggested earlier being applied.)

The code handles the following case:

<package id="foo" name="Foo App" revision="1" priority="2" depends="bar">
<package id="bar" name="Bar App" revision="1" priority="1">

When wpkg.js looks for applications to install, it reads the depends value and adds those applications to the list of packages if they do not already exist there. This takes place before the sort routine so a package which relies on a package of higher priority will be installed in a sensible order.

Please consider whether this could be added to the wpkg.js source code.

Yours,

Frank
--- wpkg-0.9.2test1.js  2005-12-06 17:29:43.000000000 +0000
+++ wpkg-depends.js     2005-12-06 19:33:20.000000000 +0000
@@ -502,7 +502,7 @@
     // grab currently installed package nodes
     var installedPackages = settings.selectNodes("package");
     
-    // loop over each installed package and check weither it still applies
+    // loop over each installed package and check whether it still applies
     for (var i = 0; i < installedPackages.length; i++) {
         var installedPackageNode = installedPackages(i);
         if (debug) { info("found installed package: " + 
installedPackageNode.getAttribute("id")); }
@@ -572,8 +572,8 @@
     
     // sorting complete
     packageArray = sortedPackages;
-    
-    // loop over each available package and determine weither to install or
+
+    // loop over each available package and determine whether to install or
     // upgrade
     for (var i = 0; i < packageArray.length; i++) {
         var packageNode = packageArray[i];
@@ -1407,6 +1407,14 @@
 }
 
 /**
+ * Removes leading / trailing spaces
+ */
+function trim(string)
+{
+    return(string.replace(new RegExp("(^\\s+)|(\\s+$)"),""));
+}
+
+/**
  * Returns an array of package nodes that should be applied to the current
  * profile.
  */
@@ -1437,15 +1445,32 @@
             if (searchArray(packageArray, packageNode)) {
                 continue;
             }
-            
+
             // sometimes nodes can be null
+           var depends=null;
             if (packageNode != null) {
                 // add the new node to the array
                 packageArray.push(packageNode);
+               depends = packageNode.getAttribute("depends");
             }
+
+           // Now search all the dependencies
+            if (depends != null) {
+               var deparray=depends.split(",");
+               for (var k=0;k<deparray.length;k++) {
+                   deppack=trim(deparray[k]);
+                   var deppkg=packages.selectSingleNode("[EMAIL PROTECTED]'" +
+                       deppack + "']");
+                   if (debug) { info("Pushing "+deppack+" onto stack as 
dependent");}
+                   if (searchArray(packageArray,deppkg)) {
+                       continue;
+                   } else {
+                       packageArray.push(deppkg);
+                   }
+                }   
+           }
         }
     }
-    
     return packageArray;
 }
 

Reply via email to