X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fpkg_depends.c;h=1e14d1fb412485707d52c574b99c16d4b614fc4b;hp=10a8ab519437dafb245a74cfffbbc5ca15b1f547;hb=ac2222f7d6514fb403ce0848f6812a22a48f75c7;hpb=0f2a3b2ae317952ea4edf5a0004c698b41b0020e diff --git a/libopkg/pkg_depends.c b/libopkg/pkg_depends.c index 10a8ab5..1e14d1f 100644 --- a/libopkg/pkg_depends.c +++ b/libopkg/pkg_depends.c @@ -1,7 +1,7 @@ /* pkg_depends.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,10 +15,9 @@ General Public License for more details. */ -#include "includes.h" -#include +#include #include - + #include "pkg.h" #include "opkg_utils.h" #include "pkg_hash.h" @@ -27,7 +26,7 @@ #include "hash_table.h" #include "libbb/libbb.h" -static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str); +static int parseDepends(compound_depend_t *compound_depend, char * depend_str); static depend_t * depend_init(void); static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx); static char ** merge_unresolved(char ** oldstuff, char ** newstuff); @@ -51,9 +50,10 @@ static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata) return 0; } -/* returns ndependences or negative error value */ -int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, - pkg_vec_t *unsatisfied, char *** unresolved) +/* returns ndependencies or negative error value */ +int +pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t *unsatisfied, + char *** unresolved) { pkg_t * satisfier_entry_pkg; int i, j, k; @@ -61,19 +61,19 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, char ** the_lost; abstract_pkg_t * ab_pkg; - /* - * this is a setup to check for redundant/cyclic dependency checks, + /* + * this is a setup to check for redundant/cyclic dependency checks, * which are marked at the abstract_pkg level */ if (!(ab_pkg = pkg->parent)) { - fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name); + opkg_msg(ERROR, "Internal error, with pkg %s.\n", pkg->name); *unresolved = NULL; return 0; } if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */ *unresolved = NULL; return 0; - } else { + } else { ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */ } /**/ @@ -85,7 +85,7 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, } the_lost = NULL; - + /* foreach dependency */ for (i = 0; i < count; i++) { compound_depend_t * compound_depend = &pkg->depends[i]; @@ -100,7 +100,7 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg; abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by; int nposs = ab_provider_vec->len; - abstract_pkg_t **ab_providers = ab_provider_vec->pkgs; + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs; int l; for (l = 0; l < nposs; l++) { pkg_vec_t *test_vec = ab_providers[l]->pkgs; @@ -108,7 +108,7 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */ continue; } - + /* cruise this possiblity's pkg_vec looking for an installed version */ for (k = 0; k < test_vec->len; k++) { pkg_t *pkg_scout = test_vec->pkgs[k]; @@ -120,29 +120,38 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, int rc; pkg_vec_t *tmp_vec = pkg_vec_alloc (); /* check for not-already-installed dependencies */ - rc = pkg_hash_fetch_unsatisfied_dependencies(conf, - pkg_scout, + rc = pkg_hash_fetch_unsatisfied_dependencies(pkg_scout, tmp_vec, &newstuff); if (newstuff == NULL) { - int i; + int m; int ok = 1; - for (i = 0; i < rc; i++) { - pkg_t *p = tmp_vec->pkgs[i]; + for (m = 0; m < rc; m++) { + pkg_t *p = tmp_vec->pkgs[m]; if (p->state_want == SW_INSTALL) continue; - opkg_message(conf, OPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name); + opkg_msg(DEBUG, + "Not installing %s due" + " to requirement for %s.\n", + pkg_scout->name, + p->name); ok = 0; break; } pkg_vec_free (tmp_vec); if (ok) { /* mark this one for installation */ - opkg_message(conf, OPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name); + opkg_msg(NOTICE, + "Adding satisfier for greedy" + " dependence %s.\n", + pkg_scout->name); pkg_vec_insert(unsatisfied, pkg_scout); } } else { - opkg_message(conf, OPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name); + opkg_msg(DEBUG, + "Not installing %s due to " + "broken depends.\n", + pkg_scout->name); free (newstuff); } } @@ -158,17 +167,17 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, /* foreach provided_by, which includes the abstract_pkg itself */ depend_t *dependence_to_satisfy = possible_satisfiers[j]; abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg; - pkg_t *satisfying_pkg = - pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg, - pkg_installed_and_constraint_satisfied, - dependence_to_satisfy, 1, NULL); + pkg_t *satisfying_pkg = + pkg_hash_fetch_best_installation_candidate(satisfying_apkg, + pkg_installed_and_constraint_satisfied, + dependence_to_satisfy, 1); /* 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)) { satisfying_pkg = NULL; } } - opkg_message(conf, OPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg); + opkg_msg(DEBUG, "satisfying_pkg=%p\n", satisfying_pkg); if (satisfying_pkg != NULL) { found = 1; break; @@ -182,10 +191,10 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, /* foreach provided_by, which includes the abstract_pkg itself */ depend_t *dependence_to_satisfy = possible_satisfiers[j]; abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg; - pkg_t *satisfying_pkg = - pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg, - pkg_constraint_satisfied, - dependence_to_satisfy, 1, NULL); + pkg_t *satisfying_pkg = + pkg_hash_fetch_best_installation_candidate(satisfying_apkg, + pkg_constraint_satisfied, + dependence_to_satisfy, 1); /* 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)) { @@ -197,12 +206,13 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, if (satisfying_pkg != NULL && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST) && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) { - opkg_message (conf, OPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n", - pkg->name, satisfying_pkg->name); + opkg_msg(NOTICE, "%s: ignoring recommendation for " + "%s at user request\n", + pkg->name, satisfying_pkg->name); continue; } - opkg_message(conf, OPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg); + opkg_msg(DEBUG, "satisfying_pkg=%p\n", satisfying_pkg); if (satisfying_pkg != NULL) { satisfier_entry_pkg = satisfying_pkg; break; @@ -217,25 +227,28 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST) the_lost = add_unresolved_dep(pkg, the_lost, i); else - opkg_message (conf, OPKG_NOTICE, "%s: unsatisfied recommendation for %s\n", - pkg->name, compound_depend->possibilities[0]->pkg->name); + opkg_msg(NOTICE, + "%s: unsatisfied recommendation for %s\n", + pkg->name, + compound_depend->possibilities[0]->pkg->name); } else { if (compound_depend->type == SUGGEST) { /* just mention it politely */ - opkg_message (conf, OPKG_NOTICE, "package %s suggests installing %s\n", - pkg->name, satisfier_entry_pkg->name); + opkg_msg(NOTICE, "package %s suggests installing %s\n", + pkg->name, satisfier_entry_pkg->name); } else { char ** newstuff = NULL; - + if (satisfier_entry_pkg != pkg && !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) { pkg_vec_insert(unsatisfied, satisfier_entry_pkg); - pkg_hash_fetch_unsatisfied_dependencies(conf, - satisfier_entry_pkg, + pkg_hash_fetch_unsatisfied_dependencies(satisfier_entry_pkg, unsatisfied, &newstuff); the_lost = merge_unresolved(the_lost, newstuff); + if (newstuff) + free(newstuff); } } } @@ -246,12 +259,13 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, return unsatisfied->len; } -/*checking for conflicts !in replaces - If a packages conflicts with another but is also replacing it, I should not consider it a - really conflicts - returns 0 if conflicts <> replaces or 1 if conflicts == replaces +/*checking for conflicts !in replaces + If a packages conflicts with another but is also replacing it, I should not consider it a + really conflicts + returns 0 if conflicts <> replaces or 1 if conflicts == replaces */ -int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg) +static int +is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg) { int i ; int replaces_count = pkg->replaces_count; @@ -264,7 +278,8 @@ int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg) for (i = 0; i < replaces_count; i++) { if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found - opkg_message(NULL, OPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name); + opkg_msg(DEBUG2, "Seems I've found a replace %s %s\n", + pkg_scout->name, pkg->replaces[i]->name); return 1; } } @@ -273,8 +288,7 @@ int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg) } -/* Abhaya: added support for conflicts */ -pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg) +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg) { pkg_vec_t * installed_conflicts, * test_vec; compound_depend_t * conflicts; @@ -283,15 +297,15 @@ pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg) int i, j, k; int count; abstract_pkg_t * ab_pkg; - pkg_t **pkg_scouts; - pkg_t *pkg_scout; + pkg_t **pkg_scouts; + pkg_t *pkg_scout; - /* - * this is a setup to check for redundant/cyclic dependency checks, + /* + * this is a setup to check for redundant/cyclic dependency checks, * which are marked at the abstract_pkg level */ if(!(ab_pkg = pkg->parent)){ - fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name); + opkg_msg(ERROR, "Internal error: %s not in hash table\n", pkg->name); return (pkg_vec_t *)NULL; } @@ -314,9 +328,9 @@ pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg) for(j = 0; j < conflicts->possibility_count; j++){ possible_satisfier = possible_satisfiers[j]; if (!possible_satisfier) - fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__); + opkg_msg(ERROR, "Internal error: possible_satisfier=NULL\n"); if (!possible_satisfier->pkg) - fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__); + opkg_msg(ERROR, "Internal error: possible_satisfier->pkg=NULL\n"); test_vec = possible_satisfier->pkg->pkgs; if (test_vec) { /* pkg_vec found, it is an actual package conflict @@ -325,8 +339,8 @@ pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg) for(k = 0; k < test_vec->len; k++){ pkg_scout = pkg_scouts[k]; if (!pkg_scout) { - fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__); - continue; + opkg_msg(ERROR, "Internal error: pkg_scout=NULL\n"); + continue; } if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) && version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){ @@ -363,32 +377,32 @@ int version_constraints_satisfied(depend_t * depends, pkg_t * pkg) free (temp->version); free(temp); - if((depends->constraint == EARLIER) && + if((depends->constraint == EARLIER) && (comparison < 0)) return 1; - else if((depends->constraint == LATER) && + else if((depends->constraint == LATER) && (comparison > 0)) return 1; else if(comparison == 0) return 1; - else if((depends->constraint == LATER_EQUAL) && + else if((depends->constraint == LATER_EQUAL) && (comparison >= 0)) return 1; - else if((depends->constraint == EARLIER_EQUAL) && + else if((depends->constraint == EARLIER_EQUAL) && (comparison <= 0)) return 1; - + return 0; } -int pkg_dependence_satisfiable(opkg_conf_t *conf, depend_t *depend) +int pkg_dependence_satisfiable(depend_t *depend) { abstract_pkg_t *apkg = depend->pkg; abstract_pkg_vec_t *provider_apkgs = apkg->provided_by; int n_providers = provider_apkgs->len; abstract_pkg_t **apkgs = provider_apkgs->pkgs; pkg_vec_t *pkg_vec; - int n_pkgs ; + int n_pkgs ; int i; int j; @@ -408,7 +422,7 @@ int pkg_dependence_satisfiable(opkg_conf_t *conf, depend_t *depend) return 0; } -int pkg_dependence_satisfied(opkg_conf_t *conf, depend_t *depend) +int pkg_dependence_satisfied(depend_t *depend) { abstract_pkg_t *apkg = depend->pkg; abstract_pkg_vec_t *provider_apkgs = apkg->provided_by; @@ -542,28 +556,27 @@ static char ** merge_unresolved(char ** oldstuff, char ** newstuff) return result; } -/* +/* * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre) - * this is null terminated, no count is carried around + * this is null terminated, no count is carried around */ char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx) { int count; char ** resized; - char *depend_str = pkg_depend_str(pkg, ref_ndx); count = 0; while(the_lost && the_lost[count]) count++; count++; /* need one to hold the null */ resized = xrealloc(the_lost, sizeof(char *) * (count + 1)); - resized[count - 1] = xstrdup(depend_str); + resized[count - 1] = pkg_depend_str(pkg, ref_ndx); resized[count] = NULL; - + return resized; } -void buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) +void buildProvides(abstract_pkg_t * ab_pkg, pkg_t * pkg) { int i; @@ -574,17 +587,19 @@ void buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) pkg->provides[0] = ab_pkg; for (i=1; iprovides_count; i++) { - abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name( pkg->provides_str[i-1]); + free(pkg->provides_str[i-1]); pkg->provides[i] = provided_abpkg; abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg); } + if (pkg->provides_str) + free(pkg->provides_str); } -/* Abhaya: added conflicts support */ -void buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) +void buildConflicts(pkg_t * pkg) { int i; compound_depend_t * conflicts; @@ -595,13 +610,15 @@ void buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) conflicts = pkg->conflicts = xcalloc(pkg->conflicts_count, sizeof(compound_depend_t)); for (i = 0; i < pkg->conflicts_count; i++) { conflicts->type = CONFLICTS; - parseDepends(conflicts, hash, - pkg->conflicts_str[i]); + parseDepends(conflicts, pkg->conflicts_str[i]); + free(pkg->conflicts_str[i]); conflicts++; } + if (pkg->conflicts_str) + free(pkg->conflicts_str); } -void buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) +void buildReplaces(abstract_pkg_t * ab_pkg, pkg_t * pkg) { int i; @@ -611,9 +628,10 @@ void buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) pkg->replaces = xcalloc(pkg->replaces_count, sizeof(abstract_pkg_t *)); for(i = 0; i < pkg->replaces_count; i++){ - abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]); + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(pkg->replaces_str[i]); pkg->replaces[i] = old_abpkg; + free(pkg->replaces_str[i]); if (!old_abpkg->replaced_by) old_abpkg->replaced_by = abstract_pkg_vec_alloc(); @@ -623,11 +641,14 @@ void buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) if (pkg_conflicts_abstract(pkg, old_abpkg)) abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg); } + + if (pkg->replaces_str) + free(pkg->replaces_str); } -void buildDepends(hash_table_t * hash, pkg_t * pkg) +void buildDepends(pkg_t * pkg) { - int count; + unsigned int count; int i; compound_depend_t * depends; @@ -637,116 +658,177 @@ void buildDepends(hash_table_t * hash, pkg_t * pkg) depends = pkg->depends = xcalloc(count, sizeof(compound_depend_t)); for(i = 0; i < pkg->pre_depends_count; i++){ - parseDepends(depends, hash, pkg->pre_depends_str[i]); + parseDepends(depends, pkg->pre_depends_str[i]); + free(pkg->pre_depends_str[i]); depends->type = PREDEPEND; depends++; } + if (pkg->pre_depends_str) + free(pkg->pre_depends_str); for(i = 0; i < pkg->depends_count; i++){ - parseDepends(depends, hash, pkg->depends_str[i]); + parseDepends(depends, pkg->depends_str[i]); + free(pkg->depends_str[i]); depends++; } + if (pkg->depends_str) + free(pkg->depends_str); for(i = 0; i < pkg->recommends_count; i++){ - parseDepends(depends, hash, pkg->recommends_str[i]); + parseDepends(depends, pkg->recommends_str[i]); + free(pkg->recommends_str[i]); depends->type = RECOMMEND; depends++; } + if(pkg->recommends_str) + free(pkg->recommends_str); for(i = 0; i < pkg->suggests_count; i++){ - parseDepends(depends, hash, pkg->suggests_str[i]); + parseDepends(depends, pkg->suggests_str[i]); + free(pkg->suggests_str[i]); depends->type = SUGGEST; depends++; } + if(pkg->suggests_str) + free(pkg->suggests_str); +} + +const char* +constraint_to_str(enum version_constraint c) +{ + switch (c) { + case NONE: + return ""; + case EARLIER: + return "< "; + case EARLIER_EQUAL: + return "<= "; + case EQUAL: + return "= "; + case LATER_EQUAL: + return ">= "; + case LATER: + return "> "; + } + + return ""; } /* - * pkg_depend_string: returns the depends string specified by index. - * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0. - * [0,npredepends) -> returns pre_depends_str[index] - * [npredepends,npredepends+nrecommends) -> returns recommends_str[index] - * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index] - * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index] + * Returns a printable string for pkg's dependency at the specified idx. The + * resultant string must be passed to free() by the caller. */ -char *pkg_depend_str(pkg_t *pkg, int index) +char * +pkg_depend_str(pkg_t *pkg, int idx) { - if (index < pkg->pre_depends_count) { - return pkg->pre_depends_str[index]; - } - index -= pkg->pre_depends_count; + int i; + unsigned int len; + char *str; + compound_depend_t *cdep; + depend_t *dep; - if (index < pkg->depends_count) { - return pkg->depends_str[index]; - } - index -= pkg->depends_count; + len = 0; + cdep = &pkg->depends[idx]; - if (index < pkg->recommends_count) { - return pkg->recommends_str[index]; - } - index -= pkg->recommends_count; + /* calculate string length */ + for (i=0; ipossibility_count; i++) { + dep = cdep->possibilities[i]; - if (index < pkg->suggests_count) { - return pkg->suggests_str[index]; - } + if (i != 0) + len += 3; /* space, pipe, space */ + + len += strlen(dep->pkg->name); + + if (dep->version) { + len += 2; /* space, left parenthesis */ + len += 3; /* constraint string (<=, >=, etc), space */ + len += strlen(dep->version); + len += 1; /* right parenthesis */ + } + } + + str = xmalloc(len + 1); /* +1 for the NULL terminator */ + str[0] = '\0'; + + for (i=0; ipossibility_count; i++) { + dep = cdep->possibilities[i]; + + if (i != 0) + strncat(str, " | ", len); - fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name); - return NULL; + strncat(str, dep->pkg->name, len); + + if (dep->version) { + strncat(str, " (", len); + strncat(str, constraint_to_str(dep->constraint), len); + strncat(str, dep->version, len); + strncat(str, ")", len); + } + } + + return str; } -/* - * WARNING: This function assumes pre_depends and depends are at the - * start of the pkg->depends array. - */ void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg) { - compound_depend_t * depends; - int count, othercount; - int i, j; - abstract_pkg_t * ab_depend; - abstract_pkg_t ** temp; + compound_depend_t * depends; + int count, othercount; + int i, j; + abstract_pkg_t * ab_depend; + abstract_pkg_t ** temp; + + count = pkg->pre_depends_count + + pkg->depends_count + + pkg->recommends_count + + pkg->suggests_count; + + for (i = 0; i < count; i++) { + depends = &pkg->depends[i]; + if (depends->type != PREDEPEND + && depends->type != DEPEND + && depends->type != RECOMMEND) + continue; + for (j = 0; j < depends->possibility_count; j++) { + ab_depend = depends->possibilities[j]->pkg; + if (!ab_depend->depended_upon_by) { + ab_depend->depended_upon_by = + xcalloc(1, sizeof(abstract_pkg_t *)); + } - count = pkg->pre_depends_count + pkg->depends_count; - depends = pkg->depends; + temp = ab_depend->depended_upon_by; + othercount = 1; + while (*temp) { + temp++; + othercount++; + } + *temp = ab_pkg; - for (i = 0; i < count; i++) { - for (j = 0; j < depends->possibility_count; j++){ - ab_depend = depends->possibilities[j]->pkg; - if(!ab_depend->depended_upon_by) - ab_depend->depended_upon_by = xcalloc(1, sizeof(abstract_pkg_t *)); - - temp = ab_depend->depended_upon_by; - othercount = 1; - while(*temp){ - temp++; - othercount++; - } - *temp = ab_pkg; + ab_depend->depended_upon_by = + xrealloc(ab_depend->depended_upon_by, + (othercount + 1) * sizeof(abstract_pkg_t *)); - ab_depend->depended_upon_by = xrealloc(ab_depend->depended_upon_by, - (othercount + 1) * sizeof(abstract_pkg_t *)); - /* the array may have moved */ - temp = ab_depend->depended_upon_by + othercount; - *temp = NULL; - } - depends++; - } + /* the array may have been moved by realloc */ + temp = ab_depend->depended_upon_by + othercount; + *temp = NULL; + } + } } static depend_t * depend_init(void) { - depend_t * d = xcalloc(1, sizeof(depend_t)); + depend_t * d = xcalloc(1, sizeof(depend_t)); d->constraint = NONE; d->version = NULL; d->pkg = NULL; - + return d; } -static int parseDepends(compound_depend_t *compound_depend, - hash_table_t * hash, char * depend_str) +static int parseDepends(compound_depend_t *compound_depend, + char * depend_str) { char * pkg_name, buffer[2048]; - int num_of_ors = 0; + unsigned int num_of_ors = 0; int i; char * src, * dest; depend_t ** possibilities; @@ -776,11 +858,9 @@ static int parseDepends(compound_depend_t *compound_depend, *dest++ = *src++; *dest = '\0'; pkg_name = trim_xstrdup(buffer); - if (pkg_name == NULL ) - return -ENOMEM; - + /* now look at possible version info */ - + /* skip to next chars */ if(isspace(*src)) while(*src && isspace(*src)) src++; @@ -815,7 +895,7 @@ static int parseDepends(compound_depend_t *compound_depend, } else if(!strncmp(src, ">", 1)){ possibilities[i]->constraint = LATER_EQUAL; - src++; + src++; } /* now we have any constraint, pass space to version string */ @@ -826,20 +906,14 @@ static int parseDepends(compound_depend_t *compound_depend, while(*src && *src != ')') *dest++ = *src++; *dest = '\0'; - - possibilities[i]->version = trim_xstrdup(buffer); - /* fprintf(stderr, "let's print the depends version string:"); - fprintf(stderr, "version %s\n", possibilities[i]->version);*/ - if (possibilities[i]->version == NULL ) - return -ENOMEM; - + possibilities[i]->version = trim_xstrdup(buffer); } /* hook up the dependency to its abstract pkg */ - possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name); + possibilities[i]->pkg = ensure_abstract_pkg_by_name(pkg_name); free(pkg_name); - + /* now get past the ) and any possible | chars */ while(*src && (isspace(*src) ||