diff -Naur pacman-git/lib/libalpm/deps.c pacman-git.new/lib/libalpm/deps.c --- pacman-git/lib/libalpm/deps.c 2007-07-10 17:35:32.000000000 +0200 +++ pacman-git.new/lib/libalpm/deps.c 2007-07-10 15:11:26.000000000 +0200 @@ -577,13 +577,14 @@ /* populates *list with packages that need to be installed to satisfy all * dependencies (recursive) for syncpkg * - * make sure *list and *trail are already initialized + * make sure *list is already initialized + * return value of list is undefined in case of error + * Assumption: alpm_list_add adds the entry to the end of the list */ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg, - alpm_list_t *list, alpm_list_t *trail, pmtrans_t *trans, - alpm_list_t **data) + alpm_list_t *list, pmtrans_t *trans, alpm_list_t **data) { - alpm_list_t *i, *j; + alpm_list_t *i, *j, *k; alpm_list_t *targ; alpm_list_t *deps = NULL; @@ -605,14 +606,16 @@ for(i = deps; i; i = i->next) { int found = 0; pmdepmissing_t *miss = i->data; - pmpkg_t *sync = NULL; + pmdepend_t *missdep = &(miss->depend); + + pmpkg_t *sync; - /* check if one of the packages in *list already provides this dependency */ + /* 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_list_find_str(alpm_pkg_get_provides(sp), miss->depend.name)) { - _alpm_log(PM_LOG_DEBUG, _("%s provides dependency %s -- skipping"), - alpm_pkg_get_name(sp), miss->depend.name); + if(alpm_depcmp(sp, missdep)) { + _alpm_log(PM_LOG_DEBUG, _("%s satisfies dependency %s -- skipping"), + alpm_pkg_get_name(sp), missdep->name); found = 1; } } @@ -620,28 +623,18 @@ continue; } - /* find the package in one of the repositories */ - /* check literals */ - for(j = dbs_sync; !sync && j; j = j->next) { - sync = _alpm_db_get_pkgfromcache(j->data, miss->depend.name); - } - /*TODO this autoresolves the first 'provides' package... we should fix this + /*TODO this autoresolves the first 'satisfier' package... we should fix this * somehow */ - /* check provides */ - if(!sync) { - for(j = dbs_sync; !sync && j; j = j->next) { - alpm_list_t *provides; - provides = _alpm_db_whatprovides(j->data, miss->depend.name); - if(provides) { - sync = provides->data; - } - alpm_list_free(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; + found = alpm_depcmp(sync, missdep); } } - if(!sync) { + if(!found) { _alpm_log(PM_LOG_ERROR, _("cannot resolve dependencies for \"%s\" (\"%s\" is not in the package set)"), - miss->target, miss->depend.name); + miss->target, missdep->name); if(data) { if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) { _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t)); @@ -655,49 +648,37 @@ pm_errno = PM_ERR_UNSATISFIED_DEPS; goto error; } - if(_alpm_pkg_find(alpm_pkg_get_name(sync), list)) { - /* this dep is already in the target list */ - _alpm_log(PM_LOG_DEBUG, _("dependency %s is already in the target list -- skipping"), - alpm_pkg_get_name(sync)); - continue; - } - if(!_alpm_pkg_find(alpm_pkg_get_name(sync), trail)) { - /* check pmo_ignorepkg and pmo_s_ignore to make sure we haven't pulled in - * something we're not supposed to. - */ - int usedep = 1; - if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(sync))) { - pmpkg_t *dummypkg = _alpm_pkg_new(miss->target, NULL); - QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, dummypkg, sync, NULL, &usedep); - _alpm_pkg_free(dummypkg); + /* check pmo_ignorepkg and pmo_s_ignore to make sure we haven't pulled in + * something we're not supposed to. + */ + int usedep = 1; + if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(sync))) { + pmpkg_t *dummypkg = _alpm_pkg_new(miss->target, NULL); + QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, dummypkg, sync, NULL, &usedep); + _alpm_pkg_free(dummypkg); + } + if(usedep) { + _alpm_log(PM_LOG_DEBUG, _("pulling dependency %s (needed by %s)"), + alpm_pkg_get_name(sync), alpm_pkg_get_name(syncpkg)); + list = alpm_list_add(list, sync); + if(_alpm_resolvedeps(local, dbs_sync, sync, list, trans, data)) { + goto error; } - if(usedep) { - trail = alpm_list_add(trail, sync); - if(_alpm_resolvedeps(local, dbs_sync, sync, list, trail, trans, data)) { + } else { + _alpm_log(PM_LOG_ERROR, _("cannot resolve dependencies for \"%s\""), miss->target); + if(data) { + if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) { + _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t)); + FREELIST(*data); + pm_errno = PM_ERR_MEMORY; goto error; } - _alpm_log(PM_LOG_DEBUG, _("pulling dependency %s (needed by %s)"), - alpm_pkg_get_name(sync), alpm_pkg_get_name(syncpkg)); - list = alpm_list_add(list, sync); - } else { - _alpm_log(PM_LOG_ERROR, _("cannot resolve dependencies for \"%s\""), miss->target); - if(data) { - if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) { - _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t)); - FREELIST(*data); - pm_errno = PM_ERR_MEMORY; - goto error; - } - *miss = *(pmdepmissing_t *)i->data; - *data = alpm_list_add(*data, miss); - } - pm_errno = PM_ERR_UNSATISFIED_DEPS; - goto error; + *miss = *(pmdepmissing_t *)i->data; + *data = alpm_list_add(*data, miss); } - } else { - /* cycle detected -- skip it */ - _alpm_log(PM_LOG_DEBUG, _("dependency cycle detected: %s"), sync->name); + pm_errno = PM_ERR_UNSATISFIED_DEPS; + goto error; } } diff -Naur pacman-git/lib/libalpm/deps.h pacman-git.new/lib/libalpm/deps.h --- pacman-git/lib/libalpm/deps.h 2007-07-10 17:35:32.000000000 +0200 +++ pacman-git.new/lib/libalpm/deps.h 2007-07-10 15:05:40.000000000 +0200 @@ -60,7 +60,7 @@ alpm_list_t *packages); alpm_list_t *_alpm_removedeps(pmdb_t *db, alpm_list_t *targs); int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg, - alpm_list_t *list, alpm_list_t *trail, pmtrans_t *trans, + alpm_list_t *list, pmtrans_t *trans, alpm_list_t **data); #endif /* _ALPM_DEPS_H */ diff -Naur pacman-git/lib/libalpm/sync.c pacman-git.new/lib/libalpm/sync.c --- pacman-git/lib/libalpm/sync.c 2007-07-10 17:35:32.000000000 +0200 +++ pacman-git.new/lib/libalpm/sync.c 2007-07-10 15:07:40.000000000 +0200 @@ -379,7 +379,6 @@ { alpm_list_t *deps = NULL; alpm_list_t *list = NULL; /* allow checkdeps usage with trans->packages */ - alpm_list_t *trail = NULL; /* breadcrumb list to avoid running in circles */ alpm_list_t *i, *j; int ret = 0; @@ -404,7 +403,7 @@ 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, - trail, trans, data) == -1) { + trans, data) == -1) { /* pm_errno is set by resolvedeps */ ret = -1; goto cleanup; @@ -473,7 +472,6 @@ goto cleanup; } - alpm_list_free(trail); } /* We don't care about conflicts if we're just printing uris */ @@ -709,7 +707,6 @@ cleanup: alpm_list_free(list); - alpm_list_free(trail); return(ret); }