alpm_checkdeps clean-up
No bugfixes, just makes the code human-readable Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
5c21f0f152
commit
2ed6b482d2
1 changed files with 35 additions and 118 deletions
|
@ -229,6 +229,12 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
|
||||||
return(newtargs);
|
return(newtargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Little helper function for alpm_list_find */
|
||||||
|
static int satisfycmp(const void *pkg, const void *depend)
|
||||||
|
{
|
||||||
|
return(!alpm_depcmp((pmpkg_t*) pkg, (pmdepend_t*) depend));
|
||||||
|
}
|
||||||
|
|
||||||
/** Checks dependencies and returns missing ones in a list.
|
/** Checks dependencies and returns missing ones in a list.
|
||||||
* Dependencies can include versions with depmod operators.
|
* Dependencies can include versions with depmod operators.
|
||||||
* @param db pointer to the local package database
|
* @param db pointer to the local package database
|
||||||
|
@ -240,8 +246,8 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
|
||||||
alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, int reversedeps,
|
alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, int reversedeps,
|
||||||
alpm_list_t *remove, alpm_list_t *upgrade)
|
alpm_list_t *remove, alpm_list_t *upgrade)
|
||||||
{
|
{
|
||||||
alpm_list_t *i, *j, *k, *l;
|
alpm_list_t *i, *j;
|
||||||
int found = 0;
|
alpm_list_t *joined, *dblist;
|
||||||
alpm_list_t *baddeps = NULL;
|
alpm_list_t *baddeps = NULL;
|
||||||
pmdepmissing_t *miss = NULL;
|
pmdepmissing_t *miss = NULL;
|
||||||
|
|
||||||
|
@ -251,6 +257,10 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, int reversedeps,
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
joined = alpm_list_join(alpm_list_copy(remove), alpm_list_copy(upgrade));
|
||||||
|
dblist = alpm_list_diff(_alpm_db_get_pkgcache(db), joined, _alpm_pkg_cmp);
|
||||||
|
alpm_list_free(joined);
|
||||||
|
|
||||||
/* look for unsatisfied dependencies of the upgrade list */
|
/* look for unsatisfied dependencies of the upgrade list */
|
||||||
for(i = upgrade; i; i = i->next) {
|
for(i = upgrade; i; i = i->next) {
|
||||||
pmpkg_t *tp = i->data;
|
pmpkg_t *tp = i->data;
|
||||||
|
@ -262,34 +272,19 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, int reversedeps,
|
||||||
alpm_pkg_get_name(tp), alpm_pkg_get_version(tp));
|
alpm_pkg_get_name(tp), alpm_pkg_get_version(tp));
|
||||||
|
|
||||||
for(j = alpm_pkg_get_depends(tp); j; j = j->next) {
|
for(j = alpm_pkg_get_depends(tp); j; j = j->next) {
|
||||||
/* split into name/version pairs */
|
|
||||||
pmdepend_t *depend = j->data;
|
pmdepend_t *depend = j->data;
|
||||||
found = 0;
|
|
||||||
/* 1. we check the upgrade list */
|
/* 1. we check the upgrade list */
|
||||||
for(k = upgrade; k && !found; k = k->next) {
|
|
||||||
pmpkg_t *p = k->data;
|
|
||||||
found = p && alpm_depcmp(p, depend);
|
|
||||||
}
|
|
||||||
/* 2. we check database for untouched satisfying packages */
|
/* 2. we check database for untouched satisfying packages */
|
||||||
for(k = _alpm_db_get_pkgcache(db); k && !found; k = k->next) {
|
if(!alpm_list_find(upgrade, depend, satisfycmp) &&
|
||||||
pmpkg_t *p = k->data;
|
!alpm_list_find(dblist, depend, satisfycmp)) {
|
||||||
found = p && alpm_depcmp(p, depend)
|
/* Unsatisfied dependency in the upgrade list */
|
||||||
&& !_alpm_pkg_find(alpm_pkg_get_name(p), upgrade)
|
|
||||||
&& !_alpm_pkg_find(alpm_pkg_get_name(p), remove);
|
|
||||||
}
|
|
||||||
/* else if still not found... */
|
|
||||||
if(!found) {
|
|
||||||
char *missdepstring = alpm_dep_get_string(depend);
|
char *missdepstring = alpm_dep_get_string(depend);
|
||||||
_alpm_log(PM_LOG_DEBUG, "missing dependency '%s' for package '%s'\n",
|
_alpm_log(PM_LOG_DEBUG, "missing dependency '%s' for package '%s'\n",
|
||||||
missdepstring, alpm_pkg_get_name(tp));
|
missdepstring, alpm_pkg_get_name(tp));
|
||||||
free(missdepstring);
|
free(missdepstring);
|
||||||
miss = _alpm_depmiss_new(alpm_pkg_get_name(tp), depend->mod,
|
miss = _alpm_depmiss_new(alpm_pkg_get_name(tp), depend->mod,
|
||||||
depend->name, depend->version);
|
depend->name, depend->version);
|
||||||
if(!_alpm_depmiss_isin(miss, baddeps)) {
|
baddeps = alpm_list_add(baddeps, miss);
|
||||||
baddeps = alpm_list_add(baddeps, miss);
|
|
||||||
} else {
|
|
||||||
FREE(miss);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,113 +293,35 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, int reversedeps,
|
||||||
/* reversedeps handles the backwards dependencies, ie,
|
/* reversedeps handles the backwards dependencies, ie,
|
||||||
* the packages listed in the requiredby field. */
|
* the packages listed in the requiredby field. */
|
||||||
|
|
||||||
/* we check the upgrade list then the remove list in one loop */
|
alpm_list_t *modified = alpm_list_diff(_alpm_db_get_pkgcache(db), dblist, _alpm_pkg_cmp);
|
||||||
int upgr = 1; /* we are in the upgrade list */
|
|
||||||
i = upgrade;
|
for(i = dblist; i; i = i->next) {
|
||||||
while(upgr || i) {
|
pmpkg_t *lp = i->data;
|
||||||
if(!i) { /*this is the end of the upgrade list, jump to the remove list*/
|
if(lp == NULL) {
|
||||||
i = remove;
|
_alpm_log(PM_LOG_DEBUG, "null package found in localdb pkgcache\n");
|
||||||
upgr = 0;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pmpkg_t *newpkg = i->data;
|
for(j = alpm_pkg_get_depends(lp); j; j = j->next) {
|
||||||
pmpkg_t *oldpkg;
|
pmdepend_t *depend = j->data;
|
||||||
alpm_list_t *requiredby;
|
/* we won't break this depend, if it is already broken, we ignore it */
|
||||||
if(newpkg == NULL) {
|
/* 1. check upgrade list for satisfiers */
|
||||||
_alpm_log(PM_LOG_DEBUG, "null package found in package list\n");
|
/* 2. check dblist for satisfiers */
|
||||||
i = i->next;
|
if(alpm_list_find(modified, depend, satisfycmp) &&
|
||||||
continue;
|
!alpm_list_find(upgrade, depend, satisfycmp) &&
|
||||||
}
|
!alpm_list_find(dblist, depend, satisfycmp)) {
|
||||||
_alpm_log(PM_LOG_DEBUG, "checkdeps: package %s-%s\n",
|
|
||||||
alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg));
|
|
||||||
|
|
||||||
if((oldpkg = _alpm_db_get_pkgfromcache(db, alpm_pkg_get_name(newpkg))) == NULL) {
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "cannot find package installed '%s'\n",
|
|
||||||
alpm_pkg_get_name(newpkg));
|
|
||||||
i = i->next;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
requiredby = alpm_pkg_compute_requiredby(oldpkg);
|
|
||||||
for(j = requiredby; j; j = j->next) {
|
|
||||||
pmpkg_t *p;
|
|
||||||
found = 0;
|
|
||||||
|
|
||||||
if(_alpm_pkg_find(j->data, upgrade) || _alpm_pkg_find(j->data, remove)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if((p = _alpm_db_get_pkgfromcache(db, j->data)) == NULL) {
|
|
||||||
/* hmmm... package isn't installed.. */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(k = alpm_pkg_get_depends(p); k; k = k->next) {
|
|
||||||
pmdepend_t *depend = k->data;
|
|
||||||
char *missdepstring = alpm_dep_get_string(depend);
|
char *missdepstring = alpm_dep_get_string(depend);
|
||||||
|
|
||||||
if(!alpm_depcmp(oldpkg, depend)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* OK, we don't want to break this depend */
|
|
||||||
|
|
||||||
/* 1. for efficiency we check newpkg first if we are in the upgrade list */
|
|
||||||
if(upgr && alpm_depcmp(newpkg, depend)) {
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "checkdeps: dependency '%s' also satisfied by the upgraded version of '%s'\n",
|
|
||||||
missdepstring, alpm_pkg_get_name(newpkg));
|
|
||||||
free(missdepstring);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* 2. we check the upgrade targets */
|
|
||||||
int satisfied = 0;
|
|
||||||
for(l = upgrade; l; l = l->next) {
|
|
||||||
pmpkg_t *pkg = l->data;
|
|
||||||
if(pkg && alpm_depcmp(pkg, depend)) {
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "checkdeps: dependency '%s' satisfied by '%s' from the upgrade list\n",
|
|
||||||
missdepstring, alpm_pkg_get_name(pkg));
|
|
||||||
free(missdepstring);
|
|
||||||
satisfied = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(satisfied) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* 3. we check untouched installed packages to see if anything else
|
|
||||||
* satisfies this... */
|
|
||||||
for(l = _alpm_db_get_pkgcache(db); l; l = l->next) {
|
|
||||||
pmpkg_t *pkg = l->data;
|
|
||||||
|
|
||||||
if(pkg && alpm_depcmp(pkg, depend)
|
|
||||||
&& !_alpm_pkg_find(alpm_pkg_get_name(pkg), upgrade)
|
|
||||||
&& !_alpm_pkg_find(alpm_pkg_get_name(pkg), remove)) {
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "checkdeps: dependency '%s' satisfied by installed package '%s'\n",
|
|
||||||
missdepstring, alpm_pkg_get_name(pkg));
|
|
||||||
free(missdepstring);
|
|
||||||
satisfied = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(satisfied) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The transaction would break this depend, record it */
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "checkdeps: the transaction would break '%s' dependency of '%s'\n",
|
_alpm_log(PM_LOG_DEBUG, "checkdeps: the transaction would break '%s' dependency of '%s'\n",
|
||||||
missdepstring, alpm_pkg_get_name(p));
|
missdepstring, alpm_pkg_get_name(lp));
|
||||||
free(missdepstring);
|
free(missdepstring);
|
||||||
miss = _alpm_depmiss_new(p->name, depend->mod,
|
miss = _alpm_depmiss_new(lp->name, depend->mod,
|
||||||
depend->name, depend->version);
|
depend->name, depend->version);
|
||||||
if(!_alpm_depmiss_isin(miss, baddeps)) {
|
baddeps = alpm_list_add(baddeps, miss);
|
||||||
baddeps = alpm_list_add(baddeps, miss);
|
|
||||||
} else {
|
|
||||||
FREE(miss);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FREELIST(requiredby);
|
|
||||||
i = alpm_list_next(i);
|
|
||||||
}
|
}
|
||||||
|
alpm_list_free(modified);
|
||||||
}
|
}
|
||||||
|
alpm_list_free(dblist);
|
||||||
|
|
||||||
return(baddeps);
|
return(baddeps);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue