Exemplo n.º 1
0
pkg_vec_t *pkg_hash_fetch_conflicts(pkg_t * pkg)
{
    pkg_vec_t *installed_conflicts;
    abstract_pkg_t *ab_pkg;

    /*
     * this is a setup to check for redundant/cyclic dependency checks,
     * which are marked at the abstract_pkg level
     */
    ab_pkg = pkg->parent;
    if (!ab_pkg) {
        opkg_msg(ERROR, "Internal error: %s not in hash table\n", pkg->name);
        return (pkg_vec_t *) NULL;
    }

    installed_conflicts = pkg_vec_alloc();

    __pkg_hash_fetch_conflicts(pkg, installed_conflicts);
    __pkg_hash_fetch_conflictees(pkg, installed_conflicts);

    if (installed_conflicts->len)
        return installed_conflicts;
    pkg_vec_free(installed_conflicts);
    return (pkg_vec_t *) NULL;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
     ipkg_conf_t conf;
     hash_table_t *hash = &conf.pkg_hash;
     pkg_vec_t * pkg_vec;

    if (argc < 3) {
	fprintf(stderr, "Usage: %s <pkgs_file1> <pkgs_file2> [pkg_name...]\n", argv[0]);
	exit(1);
    }
    pkg_hash_init("test", hash, 1024);

    pkg_hash_add_from_file(&conf, argv[1], NULL, NULL, 0);
    pkg_hash_add_from_file(&conf, argv[2], NULL, NULL, 0);

    if (argc < 4) {
	pkg_print_info( pkg_hash_fetch_by_name_version(hash, "libc6", "2.2.3-2"), stdout);
	/*	for(i = 0; i < pkg_vec->len; i++)
		pkg_print(pkg_vec->pkgs[i], stdout);
	*/
    } else {
	int i, j, k;
	char **unresolved;

	pkg_vec_t * dep_vec;
	for (i = 3; i < argc; i++) {
	    pkg_vec = pkg_vec_fetch_by_name(hash, argv[i]);
	    if (pkg_vec == NULL) {
		fprintf(stderr, "*** WARNING: Unknown package: %s\n\n", argv[i]);
		continue;
	    }

	    for(j = 0; j < pkg_vec->len; j++){
		pkg_print_info(pkg_vec->pkgs[j], stdout);
		dep_vec = pkg_vec_alloc();
		pkg_hash_fetch_unsatisfied_dependencies(&conf,
							pkg_vec->pkgs[j],
							dep_vec,
							&unresolved);
		if(dep_vec){
		    fprintf(stderr, "and the unsatisfied dependencies are:\n");
		    for(k = 0; k < dep_vec->len; k++){
			fprintf(stderr, "%s version %s\n", dep_vec->pkgs[k]->name, dep_vec->pkgs[k]->version);
		    }
		}
		
		fputs("", stdout);
		
	    }
 	}
    }

    pkg_hash_deinit(hash);

    return 0;
}
Exemplo n.º 3
0
Arquivo: pkg_hash.c Projeto: DgINC/USP
pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
{
     abstract_pkg_t * ab_pkg;
     int arch_priority;

     if(!pkg)
	  return pkg;

     arch_priority = pkg->arch_priority;

     if (buildDepends(hash, pkg)<0){
        fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
        return NULL;
     }
     ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);

     if (set_status) {
	  if (pkg->state_status == SS_INSTALLED) {
	       ab_pkg->state_status = SS_INSTALLED;
	  } else if (pkg->state_status == SS_UNPACKED) {
	       ab_pkg->state_status = SS_UNPACKED;
	  }
     }

     if(!ab_pkg->pkgs)
	  ab_pkg->pkgs = pkg_vec_alloc();
    
     /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
     pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
     pkg->parent = ab_pkg;

     if (buildProvides(hash, ab_pkg, pkg)<0){
        fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
        return NULL;
     }
     /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
     if (buildConflicts(hash, ab_pkg, pkg)<0){
        fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
        return NULL;
     }
     if (buildReplaces(hash, ab_pkg, pkg)<0) {
        fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
        return NULL;
     }
    
     buildDependedUponBy(pkg, ab_pkg);
     return pkg;
}
Exemplo n.º 4
0
static void __pkg_hash_fetch_conflictees(pkg_t * pkg,
                                         pkg_vec_t * installed_conflicts)
{
    int i;

    pkg_vec_t *available_pkgs = pkg_vec_alloc();
    pkg_hash_fetch_all_installed(available_pkgs);

    for (i = 0; i < available_pkgs->len; i++) {
        pkg_t *cpkg = available_pkgs->pkgs[i];
        int is_new_conflict = pkg_conflicts(cpkg, pkg)
                && !is_pkg_a_provides(cpkg, pkg)
                && !is_pkg_in_pkg_vec(installed_conflicts, cpkg)
                && !pkg_replaces(pkg, cpkg);
        if (is_new_conflict)
            pkg_vec_insert(installed_conflicts, cpkg);
    }

    pkg_vec_free(available_pkgs);
}
Exemplo n.º 5
0
Arquivo: pkg_hash.c Projeto: DgINC/USP
pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg, 
						  int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
{
     int i; 
     int nprovides = 0;
     int nmatching = 0;
     pkg_vec_t *matching_pkgs = pkg_vec_alloc();
     abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
     abstract_pkg_vec_t *provided_apkg_vec;
     abstract_pkg_t **provided_apkgs;
     abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
     pkg_t *latest_installed_parent = NULL;
     pkg_t *latest_matching = NULL;
     pkg_t *held_pkg = NULL;
     pkg_t *good_pkg_by_name = NULL;

     if (matching_apkgs == NULL || providers == NULL || 
         apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
	  return NULL;

     ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);

     provided_apkg_vec = apkg->provided_by;
     nprovides = provided_apkg_vec->len;
     provided_apkgs = provided_apkg_vec->pkgs;
     if (nprovides > 1)
	  ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);

     /* accumulate all the providers */
     for (i = 0; i < nprovides; i++) {
	  abstract_pkg_t *provider_apkg = provided_apkgs[i];
	  ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
	  abstract_pkg_vec_insert(providers, provider_apkg);
     }
     nprovides = providers->len;

     for (i = 0; i < nprovides; i++) {
	  abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
	  abstract_pkg_t *replacement_apkg = NULL;
	  pkg_vec_t *vec;

	  if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
	       replacement_apkg = provider_apkg->replaced_by->pkgs[0];
	       if (provider_apkg->replaced_by->len > 1) {
		    ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n", 
				 provider_apkg->name, replacement_apkg->name);
	       }
	  }

	  if (replacement_apkg)
	       ipkg_message(conf, IPKG_DEBUG, "   replacement_apkg=%s for provider_apkg=%s\n", 
			    replacement_apkg->name, provider_apkg->name);

	  if (replacement_apkg && (replacement_apkg != provider_apkg)) {
	       if (abstract_pkg_vec_contains(providers, replacement_apkg))
		    continue;
	       else
		    provider_apkg = replacement_apkg;
	  }

	  if (!(vec = provider_apkg->pkgs)) {
	       ipkg_message(conf, IPKG_DEBUG, "   no pkgs for provider_apkg %s\n", provider_apkg->name);
	       continue;
	  }
    

	  /* now check for supported architecture */
	  {
	       int max_count = 0;
	       int i;

	       /* count packages matching max arch priority and keep track of last one */
	       for (i = 0; i < vec->len; i++) {
		    pkg_t *maybe = vec->pkgs[i];
		    ipkg_message(conf, IPKG_DEBUG, "  %s arch=%s arch_priority=%d version=%s  \n",
				 maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
		    if (maybe->arch_priority > 0)  {
			 max_count++;
			 abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
			 pkg_vec_insert(matching_pkgs, maybe);
		    }
	       }
	  }
     }

     if (matching_pkgs->len > 1)
	  pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
     if (matching_apkgs->len > 1)
	  abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);

/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
   needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
   Until now I always got the latest, but that breaks the downgrade option.
   If I stop at the first one, I would probably miss the new ones 
   Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
   or from a Packages feed.
   It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
/*Pigi*/

     for (i = 0; i < matching_pkgs->len; i++) {
	  pkg_t *matching = matching_pkgs->pkgs[i];
          if (constraint_fcn(matching, cdata)) {  /* We found it */
             ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s  \n", matching->name, matching->version) ;
             good_pkg_by_name = matching;
             if ( matching->provided_by_hand == 1 )    /* It has been provided by hand, so it is what user want */
                break;                                 
          }
     }


     for (i = 0; i < matching_pkgs->len; i++) {
	  pkg_t *matching = matching_pkgs->pkgs[i];
	  latest_matching = matching;
	  if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
	       latest_installed_parent = matching;
	  if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
	       if (held_pkg)
		    ipkg_message(conf, IPKG_ERROR, "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) {
	  ipkg_message(conf, IPKG_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];
              ipkg_message(conf, IPKG_ERROR, "    %s\n", matching->name);
	  }
	  ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
     }

     if (matching_apkgs->len > 1 && conf->verbosity > 1) {
	  ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
		       __FUNCTION__, apkg->name, matching_pkgs->len);
	  for (i = 0; i < matching_pkgs->len; i++) {
	       pkg_t *matching = matching_pkgs->pkgs[i];
	       ipkg_message(conf, IPKG_INFO, "    %s %s %s\n",
			    matching->name, matching->version, matching->architecture);
	  }
     }

     nmatching = matching_apkgs->len;

     pkg_vec_free(matching_pkgs);
     abstract_pkg_vec_free(matching_apkgs);
     abstract_pkg_vec_free(providers);

     if (good_pkg_by_name) {   /* We found a good candidate, we will install it */ 
	  return good_pkg_by_name;
     }
     if (held_pkg) {
	  ipkg_message(conf, IPKG_INFO, "  using held package %s\n", held_pkg->name);
	  return held_pkg;
     }
     if (latest_installed_parent) {
	  ipkg_message(conf, IPKG_INFO, "  using latest version of installed package %s\n", latest_installed_parent->name);
	  return latest_installed_parent;
     }
     if (nmatching > 1) {
	  ipkg_message(conf, IPKG_INFO, "  no matching pkg out of matching_apkgs=%d\n", nmatching);
	  return NULL;
     }
     if (latest_matching) {
	  ipkg_message(conf, IPKG_INFO, "  using latest matching %s %s %s\n",
		       latest_matching->name, latest_matching->version, latest_matching->architecture);
	  return latest_matching;
     }
     return NULL;
}
Exemplo n.º 6
0
/* 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;
    unsigned int k;
    int count, found;
    char **the_lost;
    abstract_pkg_t *ab_pkg;

    /*
     * this is a setup to check for redundant/cyclic dependency checks,
     * which are marked at the abstract_pkg level
     */
    ab_pkg = pkg->parent;
    if (!ab_pkg) {
        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 */
        opkg_msg(DEBUG2, "Already checked dependencies for '%s'.\n",
                 ab_pkg->name);
        *unresolved = NULL;
        return 0;
    } else {
        opkg_msg(DEBUG2, "Checking dependencies for '%s'.\n", ab_pkg->name);
        ab_pkg->dependencies_checked = 1;       /* mark it for subsequent visits */
    }
    count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count
        + pkg->suggests_count;
    if (!count) {
        *unresolved = NULL;
        return 0;
    }

    the_lost = NULL;

    /* foreach dependency */
    for (i = 0; i < count; i++) {
        compound_depend_t *compound_depend = &pkg->depends[i];
        depend_t **possible_satisfiers = compound_depend->possibilities;;
        found = 0;
        satisfier_entry_pkg = NULL;

        if (compound_depend->type == GREEDY_DEPEND) {
            /* foreach possible satisfier */
            for (j = 0; j < compound_depend->possibility_count; j++) {
                /* foreach provided_by, which includes the abstract_pkg itself */
                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;
                int l;
                for (l = 0; l < nposs; l++) {
                    pkg_vec_t *test_vec = ab_providers[l]->pkgs;
                    /* if no depends on this one, try the first package that
                     * Provides this one */
                    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];
                        /* not installed, and not already known about? */
                        int wanted = (pkg_scout->state_want != SW_INSTALL)
                                && !pkg_scout->parent->dependencies_checked
                                && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout);
                        if (wanted) {
                            char **newstuff = NULL;
                            int rc;
                            pkg_vec_t *tmp_vec = pkg_vec_alloc();
                            /* check for not-already-installed dependencies */
                            rc = pkg_hash_fetch_unsatisfied_dependencies(pkg_scout,
                                    tmp_vec, &newstuff);
                            if (newstuff == NULL) {
                                int m;
                                int ok = 1;
                                for (m = 0; m < rc; m++) {
                                    pkg_t *p = tmp_vec->pkgs[m];
                                    if (p->state_want == SW_INSTALL)
                                        continue;
                                    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_msg(NOTICE,
                                             "Adding satisfier for greedy"
                                             " dependence %s.\n",
                                             pkg_scout->name);
                                    pkg_vec_insert(unsatisfied, pkg_scout);
                                }
                            } else {
                                opkg_msg(DEBUG,
                                         "Not installing %s due to "
                                         "broken depends.\n", pkg_scout->name);
                                free(newstuff);
                            }
                        }
                    }
                }
            }

            continue;
        }

        /* foreach possible satisfier, look for installed package  */
        for (j = 0; j < compound_depend->possibility_count; j++) {
            /* 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(
                    satisfying_apkg,
                    pkg_installed_and_constraint_satisfied,
                    dependence_to_satisfy,
                    1);
            opkg_msg(DEBUG, "satisfying_pkg=%p\n", satisfying_pkg);
            if (satisfying_pkg != NULL) {
                found = 1;
                break;
            }
        }
        /* if nothing installed matches, then look for uninstalled satisfier */
        if (!found) {
            /* foreach possible satisfier, look for installed package  */
            for (j = 0; j < compound_depend->possibility_count; j++) {
                /* 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(
                        satisfying_apkg,
                        pkg_constraint_satisfied,
                        dependence_to_satisfy,
                        1);
                opkg_msg(DEBUG, "satisfying_pkg=%p\n", satisfying_pkg);
                if (!satisfying_pkg)
                    continue;

                /* user request overrides package recommendation */
                int ignore = (compound_depend->type == RECOMMEND
                            || compound_depend->type == SUGGEST)
                        && (satisfying_pkg->state_want == SW_DEINSTALL
                            || satisfying_pkg->state_want == SW_PURGE
                            || opkg_config->no_install_recommends);
                if (ignore) {
                    opkg_msg(NOTICE,
                             "%s: ignoring recommendation for "
                             "%s at user request\n", pkg->name,
                             satisfying_pkg->name);
                    continue;
                }

                /* Check for excluded packages */
                int exclude = str_list_contains(&opkg_config->exclude_list,
                                         satisfying_pkg->name);
                if (exclude) {
                    opkg_msg(NOTICE,
                             "%s: exclude required package %s at users request\n",
                             pkg->name, satisfying_pkg->name);
                    continue;
                }

                satisfier_entry_pkg = satisfying_pkg;
                break;
            }
        }

        /* we didn't find one, add something to the unsatisfied vector */
        if (!found) {
            if (!satisfier_entry_pkg) {
                /* failure to meet recommendations is not an error */
                int required = compound_depend->type != RECOMMEND
                    && compound_depend->type != SUGGEST;
                if (required)
                    the_lost = add_unresolved_dep(pkg, the_lost, i);
                else
                    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_msg(NOTICE, "package %s suggests installing %s\n",
                             pkg->name, satisfier_entry_pkg->name);
                } else {
                    char **newstuff = NULL;

                    int not_seen_before = satisfier_entry_pkg != pkg
                            && !is_pkg_in_pkg_vec(unsatisfied,
                                    satisfier_entry_pkg);
                    if (not_seen_before) {
                        pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
                        pkg_hash_fetch_unsatisfied_dependencies(satisfier_entry_pkg,
                                unsatisfied, &newstuff);
                        the_lost = merge_unresolved(the_lost, newstuff);
                        if (newstuff)
                            free(newstuff);
                    }
                }
            }
        }
    }
    *unresolved = the_lost;

    return unsatisfied->len;
}
Exemplo n.º 7
0
pkg_vec_t *pkg_hash_fetch_satisfied_dependencies(pkg_t * pkg)
{
    pkg_vec_t *satisfiers;
    int i, j;
    unsigned int k;
    int count;
    abstract_pkg_t *ab_pkg;

    satisfiers = pkg_vec_alloc();

    /*
     * this is a setup to check for redundant/cyclic dependency checks,
     * which are marked at the abstract_pkg level
     */
    ab_pkg = pkg->parent;
    if (!ab_pkg) {
        opkg_msg(ERROR, "Internal error, with pkg %s.\n", pkg->name);
        return satisfiers;
    }

    count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count
            + pkg->suggests_count;
    if (!count)
        return satisfiers;

    /* foreach dependency */
    for (i = 0; i < count; i++) {
        compound_depend_t *compound_depend = &pkg->depends[i];
        depend_t **possible_satisfiers = compound_depend->possibilities;;

        int not_required = compound_depend->type == RECOMMEND
                || compound_depend->type == SUGGEST;
        if (not_required)
            continue;

        if (compound_depend->type == GREEDY_DEPEND) {
            /* foreach possible satisfier */
            for (j = 0; j < compound_depend->possibility_count; j++) {
                /* foreach provided_by, which includes the abstract_pkg itself */
                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;
                int l;
                for (l = 0; l < nposs; l++) {
                    pkg_vec_t *test_vec = ab_providers[l]->pkgs;
                    /* if no depends on this one, try the first package that
                     * Provides this one */
                    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];
                        /* not installed, and not already known about? */
                        int not_seen_before = pkg_scout != pkg
                                && pkg_scout->state_want == SW_INSTALL;
                        if (not_seen_before)
                            pkg_vec_insert(satisfiers, pkg_scout);
                    }
                }
            }

            continue;
        }

        /* foreach possible satisfier, look for installed package  */
        for (j = 0; j < compound_depend->possibility_count; j++) {
            /* 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(satisfying_apkg,
                                                           pkg_constraint_satisfied,
                                                           dependence_to_satisfy,
                                                           0);
            int need_to_insert = satisfying_pkg != NULL
                    && satisfying_pkg != pkg
                    && (satisfying_pkg->state_want == SW_INSTALL
                        || satisfying_pkg->state_want == SW_UNKNOWN);
            if (need_to_insert)
                pkg_vec_insert(satisfiers, satisfying_pkg);
        }
    }
    return satisfiers;
}
Exemplo n.º 8
0
static int opkg_remove_dependent_pkgs(pkg_t * pkg, abstract_pkg_t ** dependents)
{
    unsigned int i;
    unsigned int a;
    int count;
    pkg_vec_t *dependent_pkgs;
    abstract_pkg_t *ab_pkg;

    ab_pkg = pkg->parent;
    if (ab_pkg == NULL) {
        opkg_msg(ERROR, "Internal error: pkg %s isn't in hash table\n",
                 pkg->name);
        return 0;
    }

    if (dependents == NULL)
        return 0;

    // here i am using the dependencies_checked
    if (ab_pkg->dependencies_checked == 2)      // variable to make out whether this package
        return 0;               // has already been encountered in the process
    // of marking packages for removal - Karthik
    ab_pkg->dependencies_checked = 2;

    count = 1;
    dependent_pkgs = pkg_vec_alloc();

    for (i = 0; dependents[i] != NULL; i++) {
        abstract_pkg_t *dep_ab_pkg = dependents[i];

        if (dep_ab_pkg->dependencies_checked == 2) {
            continue;
        }
        if (dep_ab_pkg->state_status == SS_INSTALLED) {
            for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
                pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
                if (dep_pkg->state_status == SS_INSTALLED) {
                    pkg_vec_insert(dependent_pkgs, dep_pkg);
                    count++;
                }
            }
        }
        /* 1 - to keep track of visited ab_pkgs when checking for possiblility
         * of a broken removal of pkgs.
         * 2 - to keep track of pkgs whose deps have been checked alrdy  -
         * Karthik */
    }

    if (count == 1) {
        pkg_vec_free(dependent_pkgs);
        return 0;
    }

    int err = 0;
    for (i = 0; i < dependent_pkgs->len; i++) {
        err = opkg_remove_pkg(dependent_pkgs->pkgs[i]);
        if (err)
            break;
    }
    pkg_vec_free(dependent_pkgs);
    return err;
}
Exemplo n.º 9
0
int ipkg_conf_write_status_files(ipkg_conf_t *conf)
{
     pkg_dest_list_elt_t *iter;
     pkg_dest_t *dest;
     pkg_vec_t *all;
     pkg_t *pkg;
     register int i;
     int err;

     if (conf->noaction)
	  return 0;
     for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
	  dest = iter->data;
	  dest->status_file = fopen(dest->status_file_tmp_name, "w");
	  if (dest->status_file == NULL) {
	       fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
		       __FUNCTION__, dest->status_file_name, strerror(errno));
	  }
     }

     all = pkg_vec_alloc();
     pkg_hash_fetch_available(&conf->pkg_hash, all);

     for(i = 0; i < all->len; i++) {
	  pkg = all->pkgs[i];
	  /* We don't need most uninstalled packages in the status file */
	  if (pkg->state_status == SS_NOT_INSTALLED
	      && (pkg->state_want == SW_UNKNOWN
		  || pkg->state_want == SW_DEINSTALL
		  || pkg->state_want == SW_PURGE)) {
	       continue;
	  }
	  if (!pkg) {
	    fprintf(stderr, "Null package\n");
	  }
	  if (pkg->dest == NULL) {
	       fprintf(stderr, "%s: ERROR: Can't write status for "
		       "package %s since it has a NULL dest\n",
		       __FUNCTION__, pkg->name);
	       continue;
	  }
	  if (pkg->dest->status_file) {
	       pkg_print_status(pkg, pkg->dest->status_file);
	  }
     }

     pkg_vec_free(all);

     for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
	  dest = iter->data;
	  if (dest->status_file) {
	       err = ferror(dest->status_file);
	       fclose(dest->status_file);
	       dest->status_file = NULL;
	       if (!err) {
		    file_move(dest->status_file_tmp_name, dest->status_file_name);
	       } else {
		    fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
			    "retaining old %s\n", __FUNCTION__, 
			    dest->status_file_tmp_name, dest->status_file_name);
	       }
	  }
     }

     return 0;
}