From 9ad7b1a4a8d9d1cd15ad351bcf8e60a5ffee767d Mon Sep 17 00:00:00 2001 From: Aurelien Foret Date: Mon, 2 Jan 2006 23:13:42 +0000 Subject: fixed a segfault in removdeps updated removedeps to keep in sync with pacman 2.9.x --- lib/libalpm/deps.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 44119b64..4d0dd602 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -495,27 +495,47 @@ PMList* removedeps(pmdb_t *db, PMList *targs) { PMList *i, *j, *k; PMList *newtargs = targs; + char realpkgname[255]; if(db == NULL) { return(newtargs); } for(i = targs; i; i = i->next) { - pmpkg_t *pkg = (pmpkg_t*)i->data; - for(j = pkg->depends; j; j = j->next) { + for(j = ((pmpkg_t *)i->data)->depends; j; j = j->next) { pmdepend_t depend; pmpkg_t *dep; int needed = 0; - splitdep(j->data, &depend); + + if(splitdep(j->data, &depend)) { + continue; + } + dep = db_get_pkgfromcache(db, depend.name); + if(dep == NULL) { + /* package not found... look for a provisio instead */ + k = _alpm_db_whatprovides(db, depend.name); + if(k == NULL) { + _alpm_log(PM_LOG_WARNING, "cannot find package \"%s\" or anything that provides it!", depend.name); + continue; + } + dep = db_get_pkgfromcache(db, ((pmpkg_t *)k->data)->name); + if(dep == NULL) { + _alpm_log(PM_LOG_ERROR, "dep is NULL!"); + continue; + } + FREELISTPTR(k); + } if(pkg_isin(dep, targs)) { continue; } + /* see if it was explicitly installed */ if(dep->reason == PM_PKG_REASON_EXPLICIT) { _alpm_log(PM_LOG_FLOW2, "excluding %s -- explicitly installed", dep->name); needed = 1; } + /* see if other packages need it */ for(k = dep->requiredby; k && !needed; k = k->next) { pmpkg_t *dummy = db_get_pkgfromcache(db, k->data); @@ -525,10 +545,16 @@ PMList* removedeps(pmdb_t *db, PMList *targs) } if(!needed) { char *name; + pmpkg_t *pkg = pkg_dummy(dep->name, dep->version); + if(pkg == NULL) { + _alpm_log(PM_LOG_ERROR, "could not allocate memory for a package structure"); + continue; + } asprintf(&name, "%s-%s", dep->name, dep->version); /* add it to the target list */ - db_read(db, name, INFRQ_ALL, dep); - newtargs = pm_list_add(newtargs, dep); + db_read(db, name, INFRQ_ALL, pkg); + newtargs = pm_list_add(newtargs, pkg); + _alpm_log(PM_LOG_FLOW2, "adding %s to the targets", pkg->name); newtargs = removedeps(db, newtargs); FREE(name); } -- cgit v1.2.3-2-g168b