Add error messages in case of signature error
[oweals/opkg-lede.git] / libopkg / pkg_hash.c
index a2766284e82282c917e37ca69db4c3847878d181..d15d441f54df793599179254b3d9e6f23152d369 100644 (file)
@@ -47,7 +47,6 @@ static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const
  */
 
 
-\f
 int pkg_hash_init(const char *name, hash_table_t *hash, int len)
 {
   return hash_table_init(name, hash, len);
@@ -94,10 +93,8 @@ static char *pkg_get_default_arch(opkg_conf_t *conf)
      char *def_arch = HOST_CPU_STR;            /* Default arch */
      int def_prio = 0;                         /* Other archs override this */
 
-     l = conf->arch_list.head;
-
-     while (l) {
-         nv_pair_t *nv = l->data;
+     list_for_each_entry(l , &conf->arch_list.head, node) {
+         nv_pair_t *nv = (nv_pair_t *)l->data;
          int priority = strtol(nv->value, NULL, 0);
 
          /* Check if this arch has higher priority, and is valid */
@@ -107,7 +104,6 @@ static char *pkg_get_default_arch(opkg_conf_t *conf)
               def_prio = priority;
               def_arch = nv->name;
          }
-         l = l->next;
      }
 
      return strdup(def_arch);
@@ -182,6 +178,7 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, abstract_pk
      abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
      pkg_t *latest_installed_parent = NULL;
      pkg_t *latest_matching = NULL;
+     pkg_t *priorized_matching = NULL;
      pkg_t *held_pkg = NULL;
      pkg_t *good_pkg_by_name = NULL;
 
@@ -248,7 +245,9 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, abstract_pk
                    pkg_t *maybe = vec->pkgs[i];
                    opkg_message(conf, OPKG_DEBUG, "  %s arch=%s arch_priority=%d version=%s  \n",
                                 maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
-                   if (maybe->arch_priority > 0)  {
+                    /* We make sure not to add the same package twice. Need to search for the reason why 
+                       they show up twice sometimes. */
+                   if ((maybe->arch_priority > 0) && (! pkg_vec_contains(matching_pkgs, maybe))) {
                         max_count++;
                         abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
                         pkg_vec_insert(matching_pkgs, maybe);
@@ -297,21 +296,24 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, abstract_pk
               latest_installed_parent = matching;
          if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
               if (held_pkg)
-                   opkg_message(conf, OPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER.  Using latest.\n",
+                   opkg_message(conf, OPKG_NOTICE, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER.  Using latest.\n",
                                 held_pkg->name, matching->name);
               held_pkg = matching;
          }
      }
 
      if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
-         opkg_message(conf, OPKG_ERROR, "Package=%s, %d matching providers\n",
-                      apkg->name, matching_apkgs->len);
-         for (i = 0; i < matching_apkgs->len; i++) {
-              abstract_pkg_t *matching = matching_apkgs->pkgs[i];
-              opkg_message(conf, OPKG_ERROR, "    %s\n", matching->name);
-         }
-         opkg_message(conf, OPKG_ERROR, "Please select one with opkg install or opkg flag prefer\n");
-     }
+          int prio = 0;
+          for (i = 0; i < matching_pkgs->len; i++) {
+              pkg_t *matching = matching_pkgs->pkgs[i];
+                  if (matching->arch_priority > prio) {
+                      priorized_matching = matching;
+                      prio = matching->arch_priority;
+                      opkg_message(conf, OPKG_DEBUG, "Match with priority %i    %s\n", prio, matching->name);
+                  }
+              }
+          
+          }
 
      if (matching_apkgs->len > 1 && conf->verbosity > 1) {
          opkg_message(conf, OPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
@@ -340,6 +342,11 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, abstract_pk
          opkg_message(conf, OPKG_INFO, "  using latest version of installed package %s\n", latest_installed_parent->name);
          return latest_installed_parent;
      }
+     if (priorized_matching) {
+         opkg_message(conf, OPKG_INFO, "  using priorized matching %s %s %s\n",
+                      priorized_matching->name, priorized_matching->version, priorized_matching->architecture);
+         return priorized_matching;
+     }
      if (nmatching > 1) {
          opkg_message(conf, OPKG_INFO, "  no matching pkg out of matching_apkgs=%d\n", nmatching);
          return NULL;
@@ -460,17 +467,6 @@ pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
     }
 }
 
-static int pkg_compare_names(const void *p1, const void *p2)
-{
-  const pkg_t *pkg1 = *(const pkg_t **)p1;
-  const pkg_t *pkg2 = *(const pkg_t **)p2;
-  if (pkg1->name == NULL)
-    return 1;
-  if (pkg2->name == NULL)
-    return -1;
-  return(strcmp(pkg1->name, pkg2->name));
-}
-
 
 static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
 {
@@ -489,7 +485,6 @@ static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, v
 void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
 {
     hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
-    qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
 }
 
 static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
@@ -510,7 +505,6 @@ static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entr
 void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
 {
     hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
-    qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
 }
 
 static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
@@ -648,10 +642,13 @@ int file_hash_set_file_owner(opkg_conf_t *conf, const char *file_name, pkg_t *ow
      // opkg_message(conf, OPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
      hash_table_insert(file_hash, file_name, owning_pkg); 
      if (old_owning_pkg) {
+         pkg_get_installed_files(old_owning_pkg);
          str_list_remove_elt(old_owning_pkg->installed_files, file_name);
+         pkg_free_installed_files(old_owning_pkg);
          /* mark this package to have its filelist written */
          old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
          owning_pkg->state_flag |= SF_FILELIST_CHANGED;
+         
      }
      return 0;
 }