opkg: rename opkg_clone to pkg_t_to_opkg_package_t.
[project/opkg-lede.git] / libopkg / pkg_depends.c
index bc2ac27886a19686ea318b8c43b8624e2b8773b9..bbe786815b1ae9171dd490c8ce84803304931a6c 100644 (file)
@@ -45,18 +45,6 @@ static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
 static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
 {
      depend_t *depend = (depend_t *)cdata;
-#if 0
-     pkg_t * temp = pkg_new();
-     int comparison;
-     parseVersion(temp, depend->version);
-     comparison = pkg_compare_versions(pkg, temp);
-     free(temp);
-
-     fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n", 
-            __FUNCTION__, pkg->name, pkg->version, 
-            depend, depend->constraint, depend->version,
-            comparison, version_constraints_satisfied(depend, pkg));
-#endif
      if (version_constraints_satisfied(depend, pkg))
          return 1;
      else
@@ -173,7 +161,7 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg,
               pkg_t *satisfying_pkg = 
                    pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg, 
                                                               pkg_installed_and_constraint_satisfied, 
-                                                              dependence_to_satisfy, 1);
+                                                              dependence_to_satisfy, 1, NULL);
                /* Being that I can't test constraing in pkg_hash, I will test it here */
               if (satisfying_pkg != NULL) {
                   if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
@@ -197,7 +185,7 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg,
                    pkg_t *satisfying_pkg = 
                         pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg, 
                                                                    pkg_constraint_satisfied, 
-                                                                   dependence_to_satisfy, 1);
+                                                                   dependence_to_satisfy, 1, NULL);
                     /* Being that I can't test constraing in pkg_hash, I will test it here too */
                    if (satisfying_pkg != NULL) {
                          if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
@@ -665,7 +653,7 @@ int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
     if (pkg->provides)
       return 0;
 
-    pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
+    pkg->provides = (abstract_pkg_t **)calloc((pkg->provides_count + 1), sizeof(abstract_pkg_t *));
     if (pkg->provides == NULL) {
        fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
        return -1 ;
@@ -695,8 +683,7 @@ int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
     if (!pkg->conflicts_count)
        return 0;
 
-    conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
-                                       pkg->conflicts_count);
+    conflicts = pkg->conflicts = calloc(pkg->conflicts_count, sizeof(compound_depend_t));
     if (conflicts == NULL) {
        fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
        return  -1;
@@ -705,13 +692,6 @@ int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
         conflicts->type = CONFLICTS;
         parseDepends(conflicts, hash,
                      pkg->conflicts_str[i]);
-#if 0
-        for (j = 0; j < conflicts->possibility_count; j++) {
-             depend_t *possibility = conflicts->possibilities[j];
-             abstract_pkg_t *conflicting_apkg = possibility->pkg;
-             pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
-        }
-#endif
         conflicts++;
     }
     return 0;
@@ -724,15 +704,12 @@ int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
      if (!pkg->replaces_count)
          return 0;
 
-     pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
+     pkg->replaces = (abstract_pkg_t **)calloc(pkg->replaces_count, sizeof(abstract_pkg_t *));
      if (pkg->replaces == NULL) {
         fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
         return  -1;
      }
 
-     // if (strcmp(ab_pkg->name, pkg->name))
-     //     fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
-
      for(i = 0; i < pkg->replaces_count; i++){
          abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
 
@@ -765,7 +742,7 @@ int buildDepends(hash_table_t * hash, pkg_t * pkg)
      if (0 && pkg->pre_depends_count)
          fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n", 
                  pkg->name, pkg->pre_depends_count, pkg->depends_count);
-     depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
+     depends = pkg->depends = calloc(count, sizeof(compound_depend_t));
      if (depends == NULL) {
         fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
         return  -1;
@@ -900,7 +877,7 @@ void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
 
 static depend_t * depend_init(void)
 {
-    depend_t * d = (depend_t *)malloc(sizeof(depend_t));    
+    depend_t * d = (depend_t *)calloc(1, sizeof(depend_t));    
     if ( d==NULL ){
         fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
         return NULL; 
@@ -935,7 +912,7 @@ static int parseDepends(compound_depend_t *compound_depend,
      compound_depend->type = DEPEND;
 
      compound_depend->possibility_count = num_of_ors + 1;
-     possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
+     possibilities = (depend_t **)calloc((num_of_ors + 1), sizeof(depend_t *) );
      if (!possibilities)
          return -ENOMEM;
      compound_depend->possibilities = possibilities;