alpm_list_add == alpm_list_add_last
It's time to define that alpm_list_add(list, foo) adds 'foo' to the end of 'list' and returns with 'list', because: 1. list is a list, not a set. 2. sortbydeps _needs_ an alpm_list_add definition to work properly. As a first step, I used this definition in recursedeps. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> [Dan: punctuation cleanup in commit message and code comments, added comment to alpm_list_add] Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
46ec9e3548
commit
85b06f1276
4 changed files with 26 additions and 35 deletions
|
@ -98,7 +98,7 @@ void SYMEXPORT alpm_list_free_inner(alpm_list_t *list, alpm_list_fn_free fn)
|
|||
/* Mutators */
|
||||
|
||||
/**
|
||||
* @brief Add a new item to the list.
|
||||
* @brief Add a new item to the end of the list.
|
||||
*
|
||||
* @param list the list to add to
|
||||
* @param data the new item to be added to the list
|
||||
|
|
|
@ -596,12 +596,13 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets,
|
|||
* @brief Adds unneeded dependencies to an existing list of packages.
|
||||
* By unneeded, we mean dependencies that are only required by packages in the
|
||||
* target list, so they can be safely removed.
|
||||
* If the input list was topo sorted, the output list will be topo sorted too.
|
||||
*
|
||||
* @param db package database to do dependency tracing in
|
||||
* @param *targs pointer to a list of packages
|
||||
* @param include_explicit if 0, explicitly installed packages are not included
|
||||
*/
|
||||
void _alpm_recursedeps(pmdb_t *db, alpm_list_t **targs, int include_explicit)
|
||||
void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit)
|
||||
{
|
||||
alpm_list_t *i, *j, *k;
|
||||
|
||||
|
@ -611,34 +612,24 @@ void _alpm_recursedeps(pmdb_t *db, alpm_list_t **targs, int include_explicit)
|
|||
return;
|
||||
}
|
||||
|
||||
/* TODO: the while loop should be removed if we can assume
|
||||
* that alpm_list_add (or another function) adds to the end of the list,
|
||||
* and that the target list is topo sorted (by _alpm_sortbydeps()).
|
||||
*/
|
||||
int ready = 0;
|
||||
while(!ready) {
|
||||
ready = 1;
|
||||
for(i = *targs; i; i = i->next) {
|
||||
pmpkg_t *pkg = i->data;
|
||||
for(j = alpm_pkg_get_depends(pkg); j; j = j->next) {
|
||||
pmdepend_t *depend = alpm_splitdep(j->data);
|
||||
if(depend == NULL) {
|
||||
continue;
|
||||
}
|
||||
for(k = _alpm_db_get_pkgcache(db); k; k = k->next) {
|
||||
pmpkg_t *deppkg = k->data;
|
||||
if(alpm_depcmp(deppkg,depend)
|
||||
&& can_remove_package(db, deppkg, *targs, include_explicit)) {
|
||||
_alpm_log(PM_LOG_DEBUG, "adding '%s' to the targets\n",
|
||||
alpm_pkg_get_name(deppkg));
|
||||
|
||||
/* add it to the target list */
|
||||
*targs = alpm_list_add(*targs, _alpm_pkg_dup(deppkg));
|
||||
ready = 0;
|
||||
}
|
||||
}
|
||||
FREE(depend);
|
||||
for(i = targs; i; i = i->next) {
|
||||
pmpkg_t *pkg = i->data;
|
||||
for(j = alpm_pkg_get_depends(pkg); j; j = j->next) {
|
||||
pmdepend_t *depend = alpm_splitdep(j->data);
|
||||
if(depend == NULL) {
|
||||
continue;
|
||||
}
|
||||
for(k = _alpm_db_get_pkgcache(db); k; k = k->next) {
|
||||
pmpkg_t *deppkg = k->data;
|
||||
if(alpm_depcmp(deppkg,depend)
|
||||
&& can_remove_package(db, deppkg, targs, include_explicit)) {
|
||||
_alpm_log(PM_LOG_DEBUG, "adding '%s' to the targets\n",
|
||||
alpm_pkg_get_name(deppkg));
|
||||
/* add it to the target list */
|
||||
targs = alpm_list_add(targs, _alpm_pkg_dup(deppkg));
|
||||
}
|
||||
}
|
||||
FREE(depend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ int _alpm_depmiss_isin(pmdepmissing_t *needle, alpm_list_t *haystack);
|
|||
alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode);
|
||||
alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
|
||||
alpm_list_t *packages);
|
||||
void _alpm_recursedeps(pmdb_t *db, alpm_list_t **targs, int include_explicit);
|
||||
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, pmtrans_t *trans, alpm_list_t **data);
|
||||
|
||||
|
|
|
@ -137,11 +137,6 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
|
|||
}
|
||||
}
|
||||
|
||||
if(trans->flags & PM_TRANS_FLAG_RECURSE) {
|
||||
_alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n");
|
||||
_alpm_recursedeps(db, &trans->packages, 0);
|
||||
}
|
||||
|
||||
/* re-order w.r.t. dependencies */
|
||||
_alpm_log(PM_LOG_DEBUG, "sorting by dependencies\n");
|
||||
lp = _alpm_sortbydeps(trans->packages, PM_TRANS_TYPE_REMOVE);
|
||||
|
@ -149,6 +144,11 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
|
|||
alpm_list_free(trans->packages);
|
||||
trans->packages = lp;
|
||||
|
||||
if(trans->flags & PM_TRANS_FLAG_RECURSE) {
|
||||
_alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n");
|
||||
_alpm_recursedeps(db, trans->packages, 0);
|
||||
}
|
||||
|
||||
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
|
||||
|
||||
return(0);
|
||||
|
|
Loading…
Add table
Reference in a new issue