libxbps: improve debugging messages while looking for pkgs in repos.

This commit is contained in:
Juan RP
2011-10-30 16:41:39 +01:00
parent c5d6ccde46
commit f35e1eff42
3 changed files with 55 additions and 22 deletions

View File

@ -57,7 +57,9 @@ static int
set_new_state(prop_dictionary_t dict, pkg_state_t state) set_new_state(prop_dictionary_t dict, pkg_state_t state)
{ {
const struct state *stp; const struct state *stp;
#ifdef DEBUG
const char *pkgname; const char *pkgname;
#endif
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
@ -71,10 +73,12 @@ set_new_state(prop_dictionary_t dict, pkg_state_t state)
if (!prop_dictionary_set_cstring_nocopy(dict, "state", stp->string)) if (!prop_dictionary_set_cstring_nocopy(dict, "state", stp->string))
return EINVAL; return EINVAL;
#ifdef DEBUG
if (prop_dictionary_get_cstring_nocopy(dict, "pkgname", &pkgname)) { if (prop_dictionary_get_cstring_nocopy(dict, "pkgname", &pkgname)) {
xbps_dbg_printf("%s: changed pkg state to '%s'\n", xbps_dbg_printf("%s: changed pkg state to '%s'\n",
pkgname, stp->string); pkgname, stp->string);
} }
#endif
return 0; return 0;
} }

View File

@ -33,10 +33,13 @@
static int static int
store_dependency(prop_dictionary_t transd, store_dependency(prop_dictionary_t transd,
prop_dictionary_t repo_pkgd, prop_dictionary_t repo_pkgd,
pkg_state_t repo_pkg_state) pkg_state_t repo_pkg_state,
size_t *depth)
{ {
const struct xbps_handle *xhp = xbps_handle_get();
prop_array_t array; prop_array_t array;
const char *pkgname, *pkgver, *repoloc; const char *pkgname, *pkgver, *repoloc;
size_t x;
int rv = 0; int rv = 0;
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY);
@ -68,8 +71,15 @@ store_dependency(prop_dictionary_t transd,
if (!prop_array_add(array, repo_pkgd)) if (!prop_array_add(array, repo_pkgd))
return EINVAL; return EINVAL;
xbps_dbg_printf("Added package '%s' into " if (xhp->debug) {
xbps_dbg_printf_append("\n");
xbps_dbg_printf(" ");
for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" ");
xbps_dbg_printf_append("%s: added into "
"the transaction (%s).\n", pkgver, repoloc); "the transaction (%s).\n", pkgver, repoloc);
}
return 0; return 0;
} }
@ -165,13 +175,16 @@ static int
find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
prop_array_t mrdeps, /* missing rundeps array */ prop_array_t mrdeps, /* missing rundeps array */
prop_array_t pkg_rdeps_array, /* current pkg rundeps array */ prop_array_t pkg_rdeps_array, /* current pkg rundeps array */
size_t depth) /* max recursion depth */ const char *curpkg, /* current pkgver */
size_t *depth) /* max recursion depth */
{ {
prop_dictionary_t curpkgd, tmpd; prop_dictionary_t curpkgd, tmpd;
prop_array_t curpkgrdeps; prop_array_t curpkgrdeps;
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;
pkg_state_t state; pkg_state_t state;
const struct xbps_handle *xhp = xbps_handle_get();
size_t x;
const char *reqpkg, *pkgver_q, *reason = NULL; const char *reqpkg, *pkgver_q, *reason = NULL;
char *pkgname; char *pkgname;
int rv = 0; int rv = 0;
@ -180,7 +193,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
assert(prop_object_type(mrdeps) == PROP_TYPE_ARRAY); assert(prop_object_type(mrdeps) == PROP_TYPE_ARRAY);
assert(prop_object_type(pkg_rdeps_array) == PROP_TYPE_ARRAY); assert(prop_object_type(pkg_rdeps_array) == PROP_TYPE_ARRAY);
if (depth >= MAX_DEPTH) if (*depth >= MAX_DEPTH)
return ELOOP; return ELOOP;
iter = prop_array_iterator(pkg_rdeps_array); iter = prop_array_iterator(pkg_rdeps_array);
@ -198,13 +211,13 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
rv = EINVAL; rv = EINVAL;
break; break;
} }
if (depth < 1) if (xhp->debug) {
xbps_dbg_printf(" [direct] Requires " xbps_dbg_printf("");
"dependency '%s' ", reqpkg); for (x = 0; x < *depth; x++)
else xbps_dbg_printf_append(" ");
xbps_dbg_printf(" [indirect] Requires " xbps_dbg_printf_append("%s requires dependency '%s' ",
"dependency '%s' ", reqpkg); curpkg ? curpkg : " ", reqpkg);
}
/* /*
* Pass 1: check if required dependency is already installed * Pass 1: check if required dependency is already installed
* and its version is fully matched. * and its version is fully matched.
@ -246,7 +259,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
break; break;
} }
/* Required pkgdep not installed */ /* Required pkgdep not installed */
xbps_dbg_printf_append("not installed.\n"); xbps_dbg_printf_append("not installed");
reason = "install"; reason = "install";
state = XBPS_PKG_STATE_NOT_INSTALLED; state = XBPS_PKG_STATE_NOT_INSTALLED;
} else { } else {
@ -335,8 +348,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
if (curpkgd != NULL) { if (curpkgd != NULL) {
prop_dictionary_get_cstring_nocopy(curpkgd, prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q); "pkgver", &pkgver_q);
xbps_dbg_printf_append("`%s' queued " xbps_dbg_printf_append(" (%s queued "
"in the transaction.\n", pkgver_q); "in transaction).\n", pkgver_q);
continue; continue;
} else { } else {
/* error matching required pkgdep */ /* error matching required pkgdep */
@ -383,10 +396,12 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* Set pkg transaction reason. * Set pkg transaction reason.
*/ */
prop_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason); prop_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason);
prop_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &pkgver_q);
/* /*
* Package is on repo, add it into the transaction dictionary. * Package is on repo, add it into the transaction dictionary.
*/ */
if ((rv = store_dependency(transd, curpkgd, state)) != 0) { rv = store_dependency(transd, curpkgd, state, depth);
if (rv != 0) {
xbps_dbg_printf("store_dependency failed for " xbps_dbg_printf("store_dependency failed for "
"`%s': %s\n", reqpkg, strerror(rv)); "`%s': %s\n", reqpkg, strerror(rv));
prop_object_release(curpkgd); prop_object_release(curpkgd);
@ -401,12 +416,20 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
continue; continue;
} }
prop_object_release(curpkgd); prop_object_release(curpkgd);
if (xhp->debug) {
xbps_dbg_printf("");
for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" ");
xbps_dbg_printf_append(" %s: finding dependencies:\n",
pkgver_q);
}
/* /*
* Recursively find rundeps for current pkg dictionary. * Recursively find rundeps for current pkg dictionary.
*/ */
xbps_dbg_printf("%s[%sdirect] Finding dependencies for '%s':\n", (*depth)++;
depth < 1 ? "" : " ", depth < 1 ? "" : "in", reqpkg); rv = find_repo_deps(transd, mrdeps, curpkgrdeps,
rv = find_repo_deps(transd, mrdeps, curpkgrdeps, depth++); pkgver_q, depth);
if (rv != 0) { if (rv != 0) {
xbps_dbg_printf("Error checking %s for rundeps: %s\n", xbps_dbg_printf("Error checking %s for rundeps: %s\n",
reqpkg, strerror(rv)); reqpkg, strerror(rv));
@ -414,7 +437,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
} }
} }
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
depth--; (*depth)--;
return rv; return rv;
} }
@ -426,6 +449,7 @@ xbps_repository_find_pkg_deps(prop_dictionary_t transd,
{ {
prop_array_t pkg_rdeps; prop_array_t pkg_rdeps;
const char *pkgver; const char *pkgver;
size_t depth = 0;
int rv = 0; int rv = 0;
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY);
@ -442,7 +466,8 @@ xbps_repository_find_pkg_deps(prop_dictionary_t transd,
* This will find direct and indirect deps, if any of them is not * This will find direct and indirect deps, if any of them is not
* there it will be added into the missing_deps array. * there it will be added into the missing_deps array.
*/ */
if ((rv = find_repo_deps(transd, mdeps, pkg_rdeps, 0)) != 0) { if ((rv = find_repo_deps(transd, mdeps, pkg_rdeps,
pkgver, &depth)) != 0) {
xbps_dbg_printf("Error '%s' while checking rundeps!\n", xbps_dbg_printf("Error '%s' while checking rundeps!\n",
strerror(rv)); strerror(rv));
} }

View File

@ -57,7 +57,7 @@ repository_find_pkg(const char *pattern, const char *reason)
prop_dictionary_t pkg_repod = NULL; prop_dictionary_t pkg_repod = NULL;
prop_dictionary_t transd; prop_dictionary_t transd;
prop_array_t mdeps, unsorted; prop_array_t mdeps, unsorted;
const char *pkgname; const char *pkgname, *pkgver, *repoloc;
int rv = 0; int rv = 0;
bool bypattern = false, bestpkg; bool bypattern = false, bestpkg;
pkg_state_t state = 0; pkg_state_t state = 0;
@ -111,6 +111,8 @@ repository_find_pkg(const char *pattern, const char *reason)
} }
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc);
/* /*
* Prepare required package dependencies and add them into the * Prepare required package dependencies and add them into the
* "unsorted" array in transaction dictionary. * "unsorted" array in transaction dictionary.
@ -163,6 +165,8 @@ repository_find_pkg(const char *pattern, const char *reason)
rv = errno; rv = errno;
goto out; goto out;
} }
xbps_dbg_printf("%s: added into the transaction (%s).\n",
pkgver, repoloc);
out: out:
if (pkg_repod) if (pkg_repod)