Remove dead code, sprintf_alloc() cannot fail. Opkg will exit instead.
[oweals/opkg-lede.git] / libopkg / pkg_vec.c
index 9e4f26b812d09251d1b60cd8564caec72261a835..472962c9f88cd5237b909aa75d46545f37afbf7c 100644 (file)
@@ -1,7 +1,7 @@
 /* pkg_vec.c - the opkg package management system
 
    Steven M. Ayer
-   
+
    Copyright (C) 2002 Compaq Computer Corporation
 
    This program is free software; you can redistribute it and/or
@@ -15,9 +15,9 @@
    General Public License for more details.
 */
 
-#include "includes.h"
+#include <stdio.h>
 #include <fnmatch.h>
-#include "xregex.h"
+
 #include "pkg.h"
 #include "opkg_message.h"
 #include "libbb/libbb.h"
@@ -48,54 +48,52 @@ void pkg_vec_free(pkg_vec_t *vec)
  *             so identical versions have identical version strings,
  *             implying identical packages; let's marry these
  */
-pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,opkg_conf_t *conf)
+void pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status)
 {
      int i;
      int found = 0;
 
      /* look for a duplicate pkg by name, version, and architecture */
      for (i = 0; i < vec->len; i++){
-         opkg_message(conf, OPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n", 
-                      __FUNCTION__, pkg->name, pkg->version, pkg->architecture, 
-                       vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
-         if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
-             && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
-             && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
+         opkg_msg(DEBUG2, "%s %s arch=%s vs. %s %s arch=%s.\n",
+                       pkg->name, pkg->version, pkg->architecture,
+                       vec->pkgs[i]->name, vec->pkgs[i]->version,
+                       vec->pkgs[i]->architecture);
+        /* if the name,ver,arch matches, or the name matches and the
+         * package is marked deinstall/hold  */
+         if ((!strcmp(pkg->name, vec->pkgs[i]->name))
+             && ((pkg->state_want == SW_DEINSTALL
+                 && (pkg->state_flag & SF_HOLD))
+             || ((pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
+             && (!strcmp(pkg->architecture, vec->pkgs[i]->architecture))))) {
               found  = 1;
-               opkg_message(conf, OPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
-                             __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
+               opkg_msg(DEBUG2, "Duplicate for pkg=%s version=%s arch=%s.\n",
+                       pkg->name, pkg->version, pkg->architecture);
               break;
          }
      }
 
      /* we didn't find one, add it */
-     if (!found){   
-          opkg_message(conf, OPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
-                      __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
+     if (!found){
+          opkg_msg(DEBUG2, "Adding new pkg=%s version=%s arch=%s.\n",
+                       pkg->name, pkg->version, pkg->architecture);
           pkg_vec_insert(vec, pkg);
-         return pkg;
+         return;
      }
+
      /* update the one that we have */
-     else {
-          opkg_message(conf, OPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
-                        __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
-         if (set_status) {
-              /* this is from the status file, so need to merge with existing database */
-               opkg_message(conf, OPKG_DEBUG2, " with set_status\n");
-              pkg_merge(vec->pkgs[i], pkg, set_status);
-              /* XXX: CLEANUP: It's not so polite to free something here
-                 that was passed in from above. */
-              pkg_deinit(pkg);
-              free(pkg);
-         } else {
-               opkg_message(conf, OPKG_DEBUG2, " WITHOUT set_status\n");
-              /* just overwrite the old one */
-              pkg_deinit(vec->pkgs[i]);
-              free(vec->pkgs[i]);
-              vec->pkgs[i] = pkg;
-         }
-         return vec->pkgs[i];
+     opkg_msg(DEBUG2, "Merging %s %s arch=%s, set_status=%d.\n",
+                       pkg->name, pkg->version, pkg->architecture, set_status);
+     if (set_status) {
+          /* This is from the status file,
+          * so need to merge with existing database */
+          pkg_merge(pkg, vec->pkgs[i]);
      }
+
+     /* overwrite the old one */
+     pkg_deinit(vec->pkgs[i]);
+     free(vec->pkgs[i]);
+     vec->pkgs[i] = pkg;
 }
 
 void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
@@ -149,7 +147,7 @@ int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
 
 abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
 {
-    abstract_pkg_vec_t * vec ; 
+    abstract_pkg_vec_t * vec ;
     vec = xcalloc(1, sizeof(abstract_pkg_vec_t));
     vec->pkgs = NULL;
     vec->len = 0;
@@ -177,7 +175,7 @@ void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
 
 abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
 {
-    if (vec->len > i) 
+    if (vec->len > i)
        return vec->pkgs[i];
     else
        return NULL;