Propagate errors up the call stack. Patch by Jens Erdmann <j.erdmann@road.de>.
[oweals/opkg-lede.git] / libopkg / opkg_cmd.c
index 439a8606ed29e7352d5aafbc6e509a74d5adc725..0fa471e3b43f3a7f2429d99bbb7752b62af7961c 100644 (file)
    General Public License for more details.
 */
 
+#include "config.h"
 
-#include "includes.h"
+#include <stdio.h>
 #include <dirent.h>
 #include <glob.h>
 #include <fnmatch.h>
+#include <signal.h>
+#include <unistd.h>
 
 #include "opkg_conf.h"
 #include "opkg_cmd.h"
@@ -38,7 +41,6 @@
 #include "opkg_upgrade.h"
 #include "opkg_remove.h"
 #include "opkg_configure.h"
-#include "libopkg.h"
 #include "xsystem.h"
 
 static void
@@ -302,7 +304,7 @@ opkg_recurse_pkgs_in_order(pkg_t *pkg, pkg_vec_t *all,
     /* If the  package has already been visited (by this function), skip it */
     for(j = 0; j < visited->len; j++) 
         if ( ! strcmp(visited->pkgs[j]->name, pkg->name)) {
-            opkg_msg(INFO, "pkg %s already visited, skipping.\n", pkg->name);
+            opkg_msg(DEBUG, "pkg %s already visited, skipping.\n", pkg->name);
             return 0;
         }
     
@@ -311,7 +313,7 @@ opkg_recurse_pkgs_in_order(pkg_t *pkg, pkg_vec_t *all,
     count = pkg->pre_depends_count + pkg->depends_count + \
         pkg->recommends_count + pkg->suggests_count;
 
-    opkg_msg(INFO, "pkg %s.\n", pkg->name);
+    opkg_msg(DEBUG, "pkg %s.\n", pkg->name);
 
     /* Iterate over all the dependencies of pkg. For each one, find a package 
        that is either installed or unpacked and satisfies this dependency.
@@ -326,7 +328,7 @@ opkg_recurse_pkgs_in_order(pkg_t *pkg, pkg_vec_t *all,
             l = 0;
             if (dependents != NULL)
                 while (l < abpkg->provided_by->len && dependents[l] != NULL) {
-                    opkg_msg(INFO, "Descending on pkg %s.\n", 
+                    opkg_msg(DEBUG, "Descending on pkg %s.\n", 
                                  dependents [l]->name);
     
                     /* find whether dependent l is installed or unpacked,
@@ -401,6 +403,7 @@ opkg_configure_packages(char *pkg_name)
                    pkg->state_status = SS_INSTALLED;
                    pkg->parent->state_status = SS_INSTALLED;
                    pkg->state_flag &= ~SF_PREFER;
+                   opkg_state_changed++;
               } else {
                    if (!err)
                        err = r;
@@ -423,7 +426,7 @@ error:
 static int
 opkg_install_cmd(int argc, char **argv)
 {
-     int i;
+     int i, r;
      char *arg;
      int err=0;
 
@@ -450,7 +453,9 @@ opkg_install_cmd(int argc, char **argv)
          }
      }
 
-     opkg_configure_packages(NULL);
+     r = opkg_configure_packages(NULL);
+     if (!err)
+         err = r;
 
      write_status_files_if_changed();
 
@@ -460,7 +465,7 @@ opkg_install_cmd(int argc, char **argv)
 static int
 opkg_upgrade_cmd(int argc, char **argv)
 {
-     int i;
+     int i, r;
      pkg_t *pkg;
      int err;
 
@@ -508,7 +513,9 @@ opkg_upgrade_cmd(int argc, char **argv)
          pkg_vec_free(installed);
      }
 
-     opkg_configure_packages(NULL);
+     r = opkg_configure_packages(NULL);
+     if (!err)
+         err = r;
 
      write_status_files_if_changed();
 
@@ -518,7 +525,7 @@ opkg_upgrade_cmd(int argc, char **argv)
 static int
 opkg_download_cmd(int argc, char **argv)
 {
-     int i, err;
+     int i, err = 0;
      char *arg;
      pkg_t *pkg;
 
@@ -542,7 +549,7 @@ opkg_download_cmd(int argc, char **argv)
          }
      }
 
-     return 0;
+     return err;
 }
 
 
@@ -695,7 +702,7 @@ opkg_configure_cmd(int argc, char **argv)
 static int
 opkg_remove_cmd(int argc, char **argv)
 {
-     int i, a, done;
+     int i, a, done, r, err = 0;
      pkg_t *pkg;
      pkg_t *pkg_to_remove;
      pkg_vec_t *available;
@@ -731,7 +738,10 @@ opkg_remove_cmd(int argc, char **argv)
                 opkg_msg(ERROR, "Package %s not installed.\n", pkg->name);
                  continue;
             }
-            opkg_remove_pkg(pkg_to_remove, 0);
+            r = opkg_remove_pkg(pkg_to_remove, 0);
+           if (!err)
+                err = r;
+
             done = 1;
         }
      }
@@ -742,7 +752,7 @@ opkg_remove_cmd(int argc, char **argv)
         opkg_msg(NOTICE, "No packages removed.\n");
 
      write_status_files_if_changed();
-     return 0;
+     return err;
 }
 
 static int