Remove unused parameter from pkg_hash_fetch_best_installation_candidate().
[oweals/opkg-lede.git] / libopkg / opkg_cmd.c
index 26ec73d5d5279ea94973de20b971e569bb0eabc6..ca9d9c930ea7f0a099c112eccbc6ab637d82c1f5 100644 (file)
@@ -30,7 +30,6 @@
 #include "sprintf_alloc.h"
 #include "pkg.h"
 #include "file_util.h"
-#include "str_util.h"
 #include "libbb/libbb.h"
 #include "opkg_utils.h"
 #include "opkg_defines.h"
@@ -539,7 +538,7 @@ static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv)
 
           opkg_message(conf, OPKG_DEBUG2, "Debug install_cmd: %s  \n",arg );
           err = opkg_prepare_url_for_install(conf, arg, &argv[i]);
-          if (err != EINVAL && err != 0)
+          if (err)
               return err;
      }
      pkg_info_preinstall_check(conf);
@@ -547,10 +546,8 @@ static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv)
      for (i=0; i < argc; i++) {
          arg = argv[i];
           err = opkg_install_by_name(conf, arg);
-         if (err == OPKG_PKG_HAS_NO_CANDIDATE) {
-              opkg_message(conf, OPKG_ERROR,
-                           "Cannot find package %s.\n",
-                           arg);
+         if (err) {
+              opkg_message(conf, OPKG_ERROR, "Cannot find package %s.\n", arg);
          }
      }
 
@@ -575,7 +572,7 @@ static int opkg_upgrade_cmd(opkg_conf_t *conf, int argc, char **argv)
               char *arg = argv[i];
 
                err = opkg_prepare_url_for_install(conf, arg, &arg);
-               if (err != EINVAL && err != 0)
+               if (err)
                    return err;
          }
          pkg_info_preinstall_check(conf);
@@ -632,7 +629,7 @@ static int opkg_download_cmd(opkg_conf_t *conf, int argc, char **argv)
      for (i = 0; i < argc; i++) {
          arg = argv[i];
 
-         pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg, &err);
+         pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
          if (pkg == NULL) {
               opkg_message(conf, OPKG_ERROR,
                            "Cannot find package %s.\n"
@@ -717,7 +714,9 @@ static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv)
     char *old_v, *new_v;
     for (node = active_list_next(head, head); node;node = active_list_next(head,node)) {
         _old_pkg = list_entry(node, pkg_t, list);
-        _new_pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, _old_pkg->name, NULL);
+        _new_pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, _old_pkg->name);
+       if (_new_pkg == NULL)
+               continue;
         old_v = pkg_version_str_alloc(_old_pkg);
         new_v = pkg_version_str_alloc(_new_pkg);
         printf("%s - %s - %s\n", _old_pkg->name, old_v, new_v);
@@ -759,7 +758,7 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in
                    conffile_t *cf = (conffile_t *)iter->data;
                    int modified = conffile_has_been_modified(conf, cf);
                    if (cf->value)
-                       opkg_message(conf, OPKG_NOTICE,
+                       opkg_message(conf, OPKG_INFO,
                                "conffile=%s md5sum=%s modified=%d\n",
                                 cf->name, cf->value, modified);
               }
@@ -935,61 +934,52 @@ static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv)
 
 static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv)
 {
+       int i, j, k;
+       int depends_count;
+       pkg_vec_t *available_pkgs;
+       compound_depend_t *cdep;
+       pkg_t *pkg;
+       char *str;
 
-     if (argc > 0) {
-         pkg_vec_t *available_pkgs = pkg_vec_alloc();
-         const char *rel_str = "depends on";
-         int i;
-     
-         pkg_info_preinstall_check(conf);
+       pkg_info_preinstall_check(conf);
 
-         if (conf->query_all)
+       available_pkgs = pkg_vec_alloc();
+       if (conf->query_all)
               pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
-         else
+       else
               pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
-         for (i = 0; i < argc; i++) {
-              const char *target = argv[i];
-              int j;
 
-              opkg_message(conf, OPKG_NOTICE, "target=%s\n", target);
+       for (i=0; i<argc; i++) {
+               for (j=0; j<available_pkgs->len; j++) {
+                       pkg = available_pkgs->pkgs[j];
+
+                       if (fnmatch(argv[i], pkg->name, 0) != 0)
+                               continue;
+
+                       depends_count = pkg->depends_count +
+                                       pkg->pre_depends_count +
+                                       pkg->recommends_count +
+                                       pkg->suggests_count;
+
+                       opkg_message(conf, OPKG_NOTICE, "%s depends on:\n",
+                                     pkg->name);
+
+                       for (k=0; k<depends_count; k++) {
+                               cdep = &pkg->depends[k];
+
+                               if (cdep->type != DEPEND)
+                                     continue;
+
+                               str = pkg_depend_str(pkg, k);
+                               opkg_message(conf, OPKG_NOTICE, "\t%s\n", str);
+                               free(str);
+                       }
 
-              for (j = 0; j < available_pkgs->len; j++) {
-                   pkg_t *pkg = available_pkgs->pkgs[j];
-                   if (fnmatch(target, pkg->name, 0) == 0) {
-                        int k;
-                        int count = pkg->depends_count + pkg->pre_depends_count;
-                        opkg_message(conf, OPKG_NOTICE, "What %s (arch=%s) %s\n",
-                                     target, pkg->architecture, rel_str);
-                        for (k = 0; k < count; k++) {
-                             compound_depend_t *cdepend = &pkg->depends[k];
-                             int l;
-                             for (l = 0; l < cdepend->possibility_count; l++) {
-                                  depend_t *possibility = cdepend->possibilities[l];
-                                  opkg_message(conf, OPKG_NOTICE, "    %s", possibility->pkg->name);
-                                  if (conf->verbosity >= OPKG_NOTICE) {
-                                       if (possibility->version) {
-                                            char *typestr = NULL;
-                                            opkg_message(conf, OPKG_NOTICE, " %s", possibility->version);
-                                            switch (possibility->constraint) {
-                                            case NONE: typestr = "none"; break;
-                                            case EARLIER: typestr = "<"; break;
-                                            case EARLIER_EQUAL: typestr = "<="; break;
-                                            case EQUAL: typestr = "="; break;
-                                            case LATER_EQUAL: typestr = ">="; break;
-                                            case LATER: typestr = ">"; break;
-                                            }
-                                            opkg_message(conf, OPKG_NOTICE, " (%s %s)", typestr, possibility->version);
-                                       }
-                                  }
-                                  opkg_message(conf, OPKG_NOTICE, "\n");
-                             }
-                        }
-                   }
               }
-         }
-         pkg_vec_free(available_pkgs);
-     }
-     return 0;
+       }
+
+       pkg_vec_free(available_pkgs);
+       return 0;
 }
 
 enum what_field_type {
@@ -1003,105 +993,114 @@ enum what_field_type {
 
 static int opkg_what_depends_conflicts_cmd(opkg_conf_t *conf, enum depend_type what_field_type, int recursive, int argc, char **argv)
 {
-
-     if (argc > 0) {
-         pkg_vec_t *available_pkgs = pkg_vec_alloc();
-         const char *rel_str = NULL;
-         int i;
-         int changed;
-
-         switch (what_field_type) {
-         case DEPEND: rel_str = "depends on"; break;
-         case CONFLICTS: rel_str = "conflicts with"; break;
-         case SUGGEST: rel_str = "suggests"; break;
-         case RECOMMEND: rel_str = "recommends"; break;
-         default: return -1;
-         }
+       depend_t *possibility;
+       compound_depend_t *cdep;
+       pkg_vec_t *available_pkgs;
+       pkg_t *pkg;
+       int i, j, k, l;
+       int changed, count;
+       const char *rel_str = NULL;
+       char *ver;
+
+       switch (what_field_type) {
+       case DEPEND: rel_str = "depends on"; break;
+       case CONFLICTS: rel_str = "conflicts with"; break;
+       case SUGGEST: rel_str = "suggests"; break;
+       case RECOMMEND: rel_str = "recommends"; break;
+       default: return -1;
+       }
      
-         if (conf->query_all)
+       available_pkgs = pkg_vec_alloc();
+
+       if (conf->query_all)
               pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
-         else
+       else
               pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
 
-         /* mark the root set */
-         pkg_vec_clear_marks(available_pkgs);
-         opkg_message(conf, OPKG_NOTICE, "Root set:\n");
-         for (i = 0; i < argc; i++) {
-              const char *dependee_pattern = argv[i];
-              pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
-         }
-         for (i = 0; i < available_pkgs->len; i++) {
-              pkg_t *pkg = available_pkgs->pkgs[i];
+       /* mark the root set */
+       pkg_vec_clear_marks(available_pkgs);
+       opkg_message(conf, OPKG_NOTICE, "Root set:\n");
+       for (i = 0; i < argc; i++)
+              pkg_vec_mark_if_matches(available_pkgs, argv[i]);
+
+       for (i = 0; i < available_pkgs->len; i++) {
+              pkg = available_pkgs->pkgs[i];
               if (pkg->state_flag & SF_MARKED) {
                    /* mark the parent (abstract) package */
                    pkg_mark_provides(pkg);
                    opkg_message(conf, OPKG_NOTICE, "  %s\n", pkg->name);
               }
-         }
+       }
 
-         opkg_message(conf, OPKG_NOTICE, "What %s root set\n", rel_str);
-         do {
-              int j;
-              changed = 0;
+       opkg_message(conf, OPKG_NOTICE, "What %s root set\n", rel_str);
+       do {
+               changed = 0;
 
-              for (j = 0; j < available_pkgs->len; j++) {
-                   pkg_t *pkg = available_pkgs->pkgs[j];
-                   int k;
-                   int count = ((what_field_type == CONFLICTS)
+               for (j=0; j<available_pkgs->len; j++) {
+
+                       pkg = available_pkgs->pkgs[j];
+                       count = ((what_field_type == CONFLICTS)
                                 ? pkg->conflicts_count
-                                : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
-                   /* skip this package if it is already marked */
-                   if (pkg->parent->state_flag & SF_MARKED) {
-                        continue;
-                   }
-                   for (k = 0; k < count; k++) {
-                        compound_depend_t *cdepend = 
-                             (what_field_type == CONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
-                        int l;
-                        if (what_field_type != cdepend->type)
-                                continue;
-                        for (l = 0; l < cdepend->possibility_count; l++) {
-                             depend_t *possibility = cdepend->possibilities[l];
-                             if (possibility->pkg->state_flag & SF_MARKED) {
-                                  /* mark the depending package so we won't visit it again */
-                                  pkg->state_flag |= SF_MARKED;
-                                  pkg_mark_provides(pkg);
-                                  changed++;
-
-                                  if (conf->verbosity >= OPKG_NOTICE) {
-                                       char *ver = pkg_version_str_alloc(pkg); 
-                                       opkg_message(conf, OPKG_NOTICE, "    %s", pkg->name);
-                                       opkg_message(conf, OPKG_NOTICE, " %s", ver);
-                                       opkg_message(conf, OPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
+                                : pkg->pre_depends_count +
+                                pkg->depends_count +
+                                pkg->recommends_count +
+                                pkg->suggests_count);
+
+                       /* skip this package if it is already marked */
+                       if (pkg->parent->state_flag & SF_MARKED)
+                               continue;
+
+                       for (k=0; k<count; k++) {
+                               cdep = (what_field_type == CONFLICTS)
+                                       ? &pkg->conflicts[k]
+                                       : &pkg->depends[k];
+
+                               if (what_field_type != cdep->type)
+                                       continue;
+
+                               for (l=0; l<cdep->possibility_count; l++) {
+                                       possibility = cdep->possibilities[l];
+
+                                       if ((possibility->pkg->state_flag
+                                                               & SF_MARKED)
+                                                       != SF_MARKED)
+                                               continue;
+                                       
+                                       /* mark the depending package so we
+                                       * won't visit it again */
+                                       pkg->state_flag |= SF_MARKED;
+                                       pkg_mark_provides(pkg);
+                                       changed++;
+
+                                       ver = pkg_version_str_alloc(pkg); 
+                                       opkg_message(conf, OPKG_NOTICE,
+                                                       "\t%s %s\t%s %s",
+                                                       pkg->name,
+                                                       ver,
+                                                       rel_str,
+                                                       possibility->pkg->name);
+                                       free(ver);
                                        if (possibility->version) {
-                                            char *typestr = NULL;
-                                            switch (possibility->constraint) {
-                                            case NONE: typestr = "none"; break;
-                                            case EARLIER: typestr = "<"; break;
-                                            case EARLIER_EQUAL: typestr = "<="; break;
-                                            case EQUAL: typestr = "="; break;
-                                            case LATER_EQUAL: typestr = ">="; break;
-                                            case LATER: typestr = ">"; break;
-                                            }
-                                            opkg_message(conf, OPKG_NOTICE, " (%s %s)", typestr, possibility->version);
+                                               opkg_message(conf, OPKG_NOTICE,
+                                                       " (%s%s)",
+                                                       constraint_to_str(possibility->constraint),
+                                                       possibility->version);
                                        }
-                                       free(ver);
                                        if (!pkg_dependence_satisfiable(conf, possibility))
-                                            opkg_message(conf, OPKG_NOTICE, " unsatisfiable");
-                                  }
-                                  opkg_message(conf, OPKG_NOTICE, "\n");
-                                  goto next_package;
-                             }
-                        }
-                   }
-              next_package:
-                   ;
-              }
-         } while (changed && recursive);
-         pkg_vec_free(available_pkgs);
-     }
-
-     return 0;
+                                               opkg_message(conf, OPKG_NOTICE,
+                                                       " unsatisfiable");
+                                       opkg_message(conf, OPKG_NOTICE, "\n");
+                                       goto next_package;
+                               }
+                       }
+next_package:
+                       ;
+               }
+       } while (changed && recursive);
+
+       pkg_vec_free(available_pkgs);
+
+       return 0;
 }
 
 static int pkg_mark_provides(pkg_t *pkg)