From 3b8f21423035f7bf683494a8e369b6501be8e379 Mon Sep 17 00:00:00 2001 From: Nagy Gabor Date: Thu, 29 Nov 2007 21:55:55 +0100 Subject: [PATCH] Reduce the negligence of _alpm_resolvedeps This is a not-to-commit patch NOTE: -Se is temporarily removed, because now resolvedeps doesn't have spkg param Signed-off-by: Nagy Gabor --- lib/libalpm/deps.c | 158 ++++++++++++++++++++++++---------------------------- lib/libalpm/deps.h | 4 +- lib/libalpm/sync.c | 24 ++------ 3 files changed, 82 insertions(+), 104 deletions(-) diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index ff4b9c5..138c8b5 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -511,131 +511,119 @@ void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit) } } -/* populates *list with packages that need to be installed to satisfy all - * dependencies (recursive) for syncpkg +/* populates list with packages that need to be installed to satisfy all + * dependencies for list + * in case of error return value list is undefined * * @param remove contains packages elected for removal - * make sure **list is already initialized */ -int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg, - alpm_list_t **list, alpm_list_t *remove, pmtrans_t *trans, alpm_list_t **data) +int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, alpm_list_t *list, + alpm_list_t *remove, pmtrans_t *trans, alpm_list_t **data) { - alpm_list_t *i, *j, *k; - alpm_list_t *targ; alpm_list_t *deps = NULL; ALPM_LOG_FUNC; - if(local == NULL || dbs_sync == NULL || syncpkg == NULL || list == NULL) { + if(local == NULL || dbs_sync == NULL) { return(-1); } _alpm_log(PM_LOG_DEBUG, "started resolving dependencies\n"); - targ = alpm_list_add(NULL, syncpkg); - deps = alpm_checkdeps(local, 0, remove, targ); - alpm_list_free(targ); - - if(deps == NULL) { - return(0); - } - - for(i = deps; i; i = i->next) { - int found = 0; - pmdepmissing_t *miss = i->data; - pmdepend_t *missdep = &(miss->depend); - pmpkg_t *sync = NULL; - - /* check if one of the packages in *list already satisfies this dependency */ - for(j = *list; j && !found; j = j->next) { - pmpkg_t *sp = j->data; - if(alpm_depcmp(sp, missdep)) { - char *missdepstring = alpm_dep_get_string(missdep); - _alpm_log(PM_LOG_DEBUG, "%s satisfies dependency %s -- skipping\n", - alpm_pkg_get_name(sp), missdepstring); - free(missdepstring); - found = 1; - } - } - if(found) { - continue; - } - - /* find the package in one of the repositories */ - /* check literals */ - for(j = dbs_sync; j && !found; j = j->next) { - sync = _alpm_db_get_pkgfromcache(j->data, missdep->name); - if(!sync) { - continue; - } - found = alpm_depcmp(sync, missdep) && !_alpm_pkg_find(alpm_pkg_get_name(sync), remove); - if(!found) { + while((deps = alpm_checkdeps(local, 0, remove, list))) { + alpm_list_t *i, *j, *k; + alpm_list_t *missing = NULL; + alpm_list_t *newtargs = NULL; + /* This loop computes 'missing' (unresolvable missing dependencies) and + * 'newtargs' (to-be-added packages) from 'deps' */ + for(i = deps; i; i = i->next) { + int found = 0; + pmdepmissing_t *miss = i->data; + pmdepend_t *missdep = &(miss->depend); + pmpkg_t *sync = NULL; + + /* check if one of the packages in newtargs already satisfies this dependency */ + if(alpm_list_find(newtargs, missdep, satisfycmp)) { continue; } - /* If package is in the ignorepkg list, ask before we pull it */ - if(_alpm_pkg_should_ignore(sync)) { - pmpkg_t *dummypkg = _alpm_pkg_new(miss->target, NULL); - QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, dummypkg, sync, NULL, &found); - _alpm_pkg_free(dummypkg); - } - } - /*TODO this autoresolves the first 'satisfier' package... we should fix this - * somehow */ - /* check provides */ - for(j = dbs_sync; j && !found; j = j->next) { - for(k = _alpm_db_get_pkgcache(j->data); k && !found; k = k->next) { - sync = k->data; + + /* find a satisfier package in one of the repositories */ + /* check literals */ + for(j = dbs_sync; j && !found; j = j->next) { + sync = _alpm_db_get_pkgfromcache(j->data, missdep->name); if(!sync) { continue; } - found = alpm_depcmp(sync, missdep); found = alpm_depcmp(sync, missdep) && !_alpm_pkg_find(alpm_pkg_get_name(sync), remove); if(!found) { continue; } + /* If package is in the ignorepkg list, ask before we pull it */ if(_alpm_pkg_should_ignore(sync)) { pmpkg_t *dummypkg = _alpm_pkg_new(miss->target, NULL); QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, dummypkg, sync, NULL, &found); _alpm_pkg_free(dummypkg); } } - } + /*TODO this autoresolves the first 'satisfier' package... we should fix this + * somehow */ + /* check provides */ + for(j = dbs_sync; j && !found; j = j->next) { + for(k = _alpm_db_get_pkgcache(j->data); k && !found; k = k->next) { + sync = k->data; + if(!sync) { + continue; + } + found = alpm_depcmp(sync, missdep) && !_alpm_pkg_find(alpm_pkg_get_name(sync), remove); + if(!found) { + continue; + } + if(_alpm_pkg_should_ignore(sync)) { + pmpkg_t *dummypkg = _alpm_pkg_new(miss->target, NULL); + QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, dummypkg, sync, NULL, &found); + _alpm_pkg_free(dummypkg); + } + } + } - if(!found) { - char *missdepstring = alpm_dep_get_string(missdep); - _alpm_log(PM_LOG_ERROR, _("cannot resolve \"%s\", a dependency of \"%s\"\n"), - missdepstring, miss->target); - free(missdepstring); - if(data) { + if(!found) { + char *missdepstring = alpm_dep_get_string(missdep); + _alpm_log(PM_LOG_ERROR, _("cannot resolve \"%s\", a dependency of \"%s\"\n"), + missdepstring, miss->target); + free(missdepstring); if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) { _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %zd bytes\n"), sizeof(pmdepmissing_t)); - FREELIST(*data); pm_errno = PM_ERR_MEMORY; - goto error; + FREELIST(deps); + FREELIST(missing); + alpm_list_free(newtargs); + return(-1); } *miss = *(pmdepmissing_t *)i->data; - *data = alpm_list_add(*data, miss); + missing = alpm_list_add(missing, miss); + } else { + _alpm_log(PM_LOG_DEBUG, "pulling dependency %s (needed by %s)\n", + alpm_pkg_get_name(sync), miss->target); + newtargs = alpm_list_add(newtargs, sync); + } + } + FREELIST(deps); + if(missing) { + if(data) { + *data = missing; + } else { + FREELIST(missing); } + _alpm_log(PM_LOG_DEBUG, "finished resolving dependencies (failure)\n"); pm_errno = PM_ERR_UNSATISFIED_DEPS; - goto error; + alpm_list_free(newtargs); + return(-1); } else { - _alpm_log(PM_LOG_DEBUG, "pulling dependency %s (needed by %s)\n", - alpm_pkg_get_name(sync), alpm_pkg_get_name(syncpkg)); - *list = alpm_list_add(*list, sync); - if(_alpm_resolvedeps(local, dbs_sync, sync, list, remove, trans, data)) { - goto error; - } + list = alpm_list_join(list, newtargs); } } - _alpm_log(PM_LOG_DEBUG, "finished resolving dependencies\n"); - - FREELIST(deps); - + _alpm_log(PM_LOG_DEBUG, "finished resolving dependencies (success)\n"); return(0); - -error: - FREELIST(deps); - return(-1); } const char SYMEXPORT *alpm_miss_get_target(const pmdepmissing_t *miss) diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h index e4bba8b..5b25395 100644 --- a/lib/libalpm/deps.h +++ b/lib/libalpm/deps.h @@ -55,8 +55,8 @@ pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepmod_t depmod, int _alpm_depmiss_isin(pmdepmissing_t *needle, alpm_list_t *haystack); alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode); void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit); -int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg, - alpm_list_t **list, alpm_list_t *remove, pmtrans_t *trans, alpm_list_t **data); +int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, alpm_list_t *list, + alpm_list_t *remove, pmtrans_t *trans, alpm_list_t **data); #endif /* _ALPM_DEPS_H */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index f6fa318..83a17ed 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -415,11 +415,9 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync *data = NULL; } - if(!(trans->flags & PM_TRANS_FLAG_DEPENDSONLY)) { - for(i = trans->packages; i; i = i->next) { - pmsyncpkg_t *sync = i->data; - list = alpm_list_add(list, sync->pkg); - } + for(i = trans->packages; i; i = i->next) { + pmsyncpkg_t *sync = i->data; + list = alpm_list_add(list, sync->pkg); } if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) { @@ -437,18 +435,10 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync } } - for(i = trans->packages; i; i = i->next) { - pmpkg_t *spkg = ((pmsyncpkg_t *)i->data)->pkg; - if(_alpm_resolvedeps(db_local, dbs_sync, spkg, &list, - remove, trans, data) == -1) { - /* pm_errno is set by resolvedeps */ - ret = -1; - goto cleanup; - } - } - - if((trans->flags & PM_TRANS_FLAG_DEPENDSONLY)) { - FREELIST(trans->packages); + if(_alpm_resolvedeps(db_local, dbs_sync, list, remove, trans, data) == -1) { + /* pm_errno is set by resolvedeps */ + ret = -1; + goto cleanup; } for(i = list; i; i = i->next) { -- 1.5.3.6