xbps_repository_find_pkg_deps: simplify and handle an error case.

This commit is contained in:
Juan RP 2011-01-27 18:23:32 +01:00
parent faad0a6597
commit 8a7bfe6cda

View File

@ -32,7 +32,7 @@
#include "xbps_api_impl.h" #include "xbps_api_impl.h"
static int static int
store_dependency(prop_dictionary_t trans_dict, prop_dictionary_t repo_pkgd) store_dependency(prop_dictionary_t transd, prop_dictionary_t repo_pkgd)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
prop_array_t array; prop_array_t array;
@ -40,7 +40,7 @@ store_dependency(prop_dictionary_t trans_dict, prop_dictionary_t repo_pkgd)
int rv = 0; int rv = 0;
pkg_state_t state = 0; pkg_state_t state = 0;
assert(trans_dict != NULL); assert(transd != NULL);
assert(repo_pkgd != NULL); assert(repo_pkgd != NULL);
/* /*
* Get some info about dependencies and current repository. * Get some info about dependencies and current repository.
@ -53,7 +53,7 @@ store_dependency(prop_dictionary_t trans_dict, prop_dictionary_t repo_pkgd)
if (dict == NULL) if (dict == NULL)
return errno; return errno;
array = prop_dictionary_get(trans_dict, "unsorted_deps"); array = prop_dictionary_get(transd, "unsorted_deps");
if (array == NULL) { if (array == NULL) {
prop_object_release(dict); prop_object_release(dict);
return errno; return errno;
@ -236,7 +236,7 @@ out:
} }
static int static int
find_repo_deps(prop_dictionary_t trans_dict, /* 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 */
const char *originpkgn, /* origin pkgname */ const char *originpkgn, /* origin pkgname */
prop_array_t pkg_rdeps_array) /* current pkg rundeps array */ prop_array_t pkg_rdeps_array) /* current pkg rundeps array */
@ -246,7 +246,7 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;
pkg_state_t state = 0; pkg_state_t state = 0;
const char *reqpkg, *reqvers, *pkg_queued, *repopkgver; const char *reqpkg, *reqvers, *pkgver_q, *repopkgver;
char *pkgname; char *pkgname;
int rv = 0; int rv = 0;
@ -288,19 +288,15 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
* array of unsorted deps, and check if current required * array of unsorted deps, and check if current required
* dependency pattern is matched. * dependency pattern is matched.
*/ */
curpkgd = xbps_find_pkg_in_dict_by_name(trans_dict, curpkgd = xbps_find_pkg_in_dict_by_pattern(transd,
"unsorted_deps", pkgname); "unsorted_deps", reqpkg);
if (curpkgd != NULL) { if (curpkgd != NULL) {
prop_dictionary_get_cstring_nocopy(curpkgd, prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkg_queued); "pkgver", &pkgver_q);
if (xbps_pkgpattern_match(pkg_queued, xbps_dbg_printf_append("`%s' queued "
__UNCONST(reqpkg))) { "in the transaction.\n", pkgver_q);
xbps_dbg_printf_append( free(pkgname);
"'%s' queued in the transaction.\n", continue;
pkg_queued);
free(pkgname);
continue;
}
} else { } else {
/* error matching required pkgdep */ /* error matching required pkgdep */
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
@ -362,7 +358,7 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
* required pkgdep version. * required pkgdep version.
*/ */
prop_dictionary_get_cstring_nocopy(tmpd, prop_dictionary_get_cstring_nocopy(tmpd,
"pkgver", &pkg_queued); "pkgver", &pkgver_q);
/* Check its state */ /* Check its state */
rv = xbps_get_pkg_state_installed(pkgname, &state); rv = xbps_get_pkg_state_installed(pkgname, &state);
@ -373,8 +369,8 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
break; break;
} }
free(pkgname); free(pkgname);
if (xbps_pkgpattern_match(pkg_queued, rv = xbps_pkgpattern_match(pkgver_q, __UNCONST(reqpkg));
__UNCONST(reqpkg)) == 0) { if (rv == 0) {
/* /*
* Package is installed but does not match * Package is installed but does not match
* the dependency pattern, an update * the dependency pattern, an update
@ -384,10 +380,10 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
"version", &repopkgver); "version", &repopkgver);
xbps_dbg_printf_append("installed `%s', " xbps_dbg_printf_append("installed `%s', "
"updating to `%s'...\n", "updating to `%s'...\n",
pkg_queued, repopkgver); pkgver_q, repopkgver);
prop_dictionary_set_cstring_nocopy(curpkgd, prop_dictionary_set_cstring_nocopy(curpkgd,
"trans-action", "update"); "trans-action", "update");
} else { } else if (rv == 1) {
if (state == XBPS_PKG_STATE_UNPACKED) { if (state == XBPS_PKG_STATE_UNPACKED) {
/* /*
* Package matches the dependency * Package matches the dependency
@ -399,25 +395,30 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
"configure"); "configure");
xbps_dbg_printf_append("installed `%s'" xbps_dbg_printf_append("installed `%s'"
", but needs to be configured...\n", ", but needs to be configured...\n",
pkg_queued); pkgver_q);
} else { } else {
/* /*
* Package matches the dependency * Package matches the dependency
* pattern and is fully installed, * pattern and is fully installed,
* skip to the next one. * skip and pass to next one.
*/ */
xbps_dbg_printf_append("installed " xbps_dbg_printf_append("installed "
"`%s'.\n", pkg_queued); "`%s'.\n", pkgver_q);
prop_object_release(tmpd); prop_object_release(tmpd);
prop_object_release(curpkgd); prop_object_release(curpkgd);
continue; continue;
} }
} else {
/* error matching pkgpattern */
prop_object_release(tmpd);
prop_object_release(curpkgd);
break;
} }
} }
/* /*
* Package is on repo, add it into the dictionary. * Package is on repo, add it into the dictionary.
*/ */
if ((rv = store_dependency(trans_dict, curpkgd)) != 0) { if ((rv = store_dependency(transd, curpkgd)) != 0) {
xbps_dbg_printf("store_dependency failed %s", xbps_dbg_printf("store_dependency failed %s",
reqpkg); reqpkg);
prop_object_release(curpkgd); prop_object_release(curpkgd);
@ -453,7 +454,7 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
xbps_dbg_printf("%sFinding dependencies for '%s' [%s]:\n", xbps_dbg_printf("%sFinding dependencies for '%s' [%s]:\n",
originpkgn ? "" : " ", reqpkg, originpkgn ? "" : " ", reqpkg,
originpkgn ? "direct" : "indirect"); originpkgn ? "direct" : "indirect");
rv = find_repo_deps(trans_dict, mrdeps, NULL, curpkg_rdeps); rv = find_repo_deps(transd, mrdeps, NULL, curpkg_rdeps);
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));
@ -466,7 +467,7 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
} }
int HIDDEN int HIDDEN
xbps_repository_find_pkg_deps(prop_dictionary_t trans_dict, xbps_repository_find_pkg_deps(prop_dictionary_t transd,
prop_array_t mdeps, prop_array_t mdeps,
prop_dictionary_t repo_pkgd) prop_dictionary_t repo_pkgd)
{ {
@ -474,7 +475,7 @@ xbps_repository_find_pkg_deps(prop_dictionary_t trans_dict,
const char *pkgname, *pkgver; const char *pkgname, *pkgver;
int rv = 0; int rv = 0;
assert(trans_dict != NULL); assert(transd != NULL);
assert(mdeps != NULL); assert(mdeps != NULL);
assert(repo_pkgd != NULL); assert(repo_pkgd != NULL);
@ -489,7 +490,7 @@ xbps_repository_find_pkg_deps(prop_dictionary_t trans_dict,
* 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(trans_dict, mdeps, pkgname, pkg_rdeps)) != 0) { if ((rv = find_repo_deps(transd, mdeps, pkgname, pkg_rdeps)) != 0) {
xbps_dbg_printf("Error '%s' while checking rundeps!\n", xbps_dbg_printf("Error '%s' while checking rundeps!\n",
strerror(rv)); strerror(rv));
} }