xbps_sort_pkg_deps: add debugging, use xbps_pkgdep_match().

--HG--
extra : convert_revision : xtraeme%40gmail.com-20091129045327-x2y95weqecbon4l4
This commit is contained in:
Juan RP 2009-11-29 05:53:27 +01:00
parent bd9b545fc9
commit 45f1d7b70a

View File

@ -42,14 +42,19 @@ static struct sorted_dependency *
find_sorteddep_by_name(const char *pkgname) find_sorteddep_by_name(const char *pkgname)
{ {
struct sorted_dependency *sdep = NULL; struct sorted_dependency *sdep = NULL;
const char *curname; const char *curpkgname;
bool found = false;
SIMPLEQ_FOREACH(sdep, &sdep_list, chain) { SIMPLEQ_FOREACH(sdep, &sdep_list, chain) {
prop_dictionary_get_cstring_nocopy(sdep->dict, prop_dictionary_get_cstring_nocopy(sdep->dict,
"pkgname", &curname); "pkgname", &curpkgname);
if (strcmp(pkgname, curname) == 0) if (strcmp(pkgname, curpkgname) == 0) {
found = true;
break; break;
}
} }
if (!found)
return NULL;
return sdep; return sdep;
} }
@ -62,8 +67,8 @@ xbps_sort_pkg_deps(prop_dictionary_t chaindeps)
prop_object_iterator_t iter, iter2; prop_object_iterator_t iter, iter2;
struct sorted_dependency *sdep; struct sorted_dependency *sdep;
size_t ndeps = 0, rundepscnt = 0, cnt = 0; size_t ndeps = 0, rundepscnt = 0, cnt = 0;
const char *pkgname, *str; const char *pkgname, *pkgver, *str;
char *curpkgnamedep; char *pkgnamedep;
int rv = 0; int rv = 0;
assert(chaindeps != NULL); assert(chaindeps != NULL);
@ -97,8 +102,16 @@ again:
rv = errno; rv = errno;
goto out; goto out;
} }
if (find_sorteddep_by_name(pkgname) != NULL) if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver)) {
rv = errno;
goto out;
}
DPRINTF(("Sorting package: %s\n", pkgver));
if (find_sorteddep_by_name(pkgname) != NULL) {
DPRINTF(("Skipping %s already queued.\n", pkgname));
continue; continue;
}
sdep = malloc(sizeof(*sdep)); sdep = malloc(sizeof(*sdep));
if (sdep == NULL) { if (sdep == NULL) {
@ -111,6 +124,8 @@ again:
*/ */
rundeps = prop_dictionary_get(obj, "run_depends"); rundeps = prop_dictionary_get(obj, "run_depends");
if (rundeps == NULL || prop_array_count(rundeps) == 0) { if (rundeps == NULL || prop_array_count(rundeps) == 0) {
DPRINTF(("Adding %s (no rundeps) into the sorted "
"queue.\n", pkgver));
sdep->dict = prop_dictionary_copy(obj); sdep->dict = prop_dictionary_copy(obj);
SIMPLEQ_INSERT_TAIL(&sdep_list, sdep, chain); SIMPLEQ_INSERT_TAIL(&sdep_list, sdep, chain);
cnt++; cnt++;
@ -126,6 +141,7 @@ again:
* Iterate over the run_depends array, and find out if they * Iterate over the run_depends array, and find out if they
* were already added in the sorted list. * were already added in the sorted list.
*/ */
DPRINTF(("Checking %s run_depends for sorting...\n", pkgver));
while ((obj2 = prop_object_iterator_next(iter2)) != NULL) { while ((obj2 = prop_object_iterator_next(iter2)) != NULL) {
str = prop_string_cstring_nocopy(obj2); str = prop_string_cstring_nocopy(obj2);
if (str == NULL) { if (str == NULL) {
@ -133,39 +149,49 @@ again:
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
curpkgnamedep = xbps_get_pkgdep_name(str); pkgnamedep = xbps_get_pkgdep_name(str);
if (curpkgnamedep == NULL) { if (pkgnamedep == NULL) {
free(sdep); free(sdep);
rv = EINVAL; rv = errno;
goto out; goto out;
} }
DPRINTF(("Required dependency %s: ", str));
/* /*
* If dependency is already installed or queued, * If dependency is already satisfied or queued,
* pass to the next one. * pass to the next one.
*/ */
if (xbps_check_is_installed_pkgname(curpkgnamedep)) if (xbps_check_is_installed_pkg(str)) {
rundepscnt++; rundepscnt++;
else if (find_sorteddep_by_name(curpkgnamedep) != NULL) DPRINTF(("installed.\n"));
} else if (find_sorteddep_by_name(pkgnamedep) != NULL) {
DPRINTF(("queued.\n"));
rundepscnt++; rundepscnt++;
} else {
free(curpkgnamedep); DPRINTF(("not installed or queued.\n"));
}
free(pkgnamedep);
} }
prop_object_iterator_release(iter2); prop_object_iterator_release(iter2);
/* Add dependency if all its required deps are already added */ /* Add dependency if all its required deps are already added */
if (prop_array_count(rundeps) == rundepscnt) { if (prop_array_count(rundeps) == rundepscnt) {
DPRINTF(("Adding package %s to the sorted queue.\n",
pkgver));
sdep->dict = prop_dictionary_copy(obj); sdep->dict = prop_dictionary_copy(obj);
SIMPLEQ_INSERT_TAIL(&sdep_list, sdep, chain); SIMPLEQ_INSERT_TAIL(&sdep_list, sdep, chain);
rundepscnt = 0; rundepscnt = 0;
cnt++; cnt++;
continue; continue;
} }
DPRINTF(("Unsorted package %s has missing rundeps.\n", pkgver));
free(sdep); free(sdep);
rundepscnt = 0; rundepscnt = 0;
} }
/* Iterate until all deps are processed. */ /* Iterate until all deps are processed. */
if (cnt < ndeps) { if (cnt < ndeps) {
DPRINTF(("Missing required deps! cnt: %zu ndeps: %zu\n",
cnt, ndeps));
prop_object_iterator_reset(iter); prop_object_iterator_reset(iter);
goto again; goto again;
} }