From a5f4848d0b17cd4a213095297a96fa0ddc837a28 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 28 Mar 2012 12:01:59 +0200 Subject: [PATCH] Use best pkg available when resolving required dependencies. --- NEWS | 3 +++ include/xbps_api.h | 2 +- lib/repository_finddeps.c | 21 +++++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index a84a7da6..00fb01a8 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ xbps-0.15 (???): + * When resolving required dependencies also find the best pkg + available in repository pool. Thanks to dave for testing! + * Started a test suite for libxbps. Tests are written for Kyua (http://code.google.com/p/kyua) and can be built and installed with the --with-tests configure option, by default will be installed diff --git a/include/xbps_api.h b/include/xbps_api.h index acfba659..1ab99178 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -56,7 +56,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.4" -#define XBPS_API_VERSION "20120324" +#define XBPS_API_VERSION "20120328" #define XBPS_VERSION "0.15" /** diff --git a/lib/repository_finddeps.c b/lib/repository_finddeps.c index dda1c1d1..96216115 100644 --- a/lib/repository_finddeps.c +++ b/lib/repository_finddeps.c @@ -38,7 +38,8 @@ store_dependency(prop_dictionary_t transd, { const struct xbps_handle *xhp = xbps_handle_get(); prop_array_t array; - const char *pkgname, *pkgver, *repoloc; + prop_dictionary_t curpkgd; + const char *pkgname, *pkgver, *repoloc, *curpkgver; size_t x; int rv = 0; @@ -50,6 +51,21 @@ store_dependency(prop_dictionary_t transd, prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(repo_pkgd, "repository", &repoloc); + /* + * Check if same pkg is already in transaction, and if current pkg version + * is greater add it, otherwise drop it. + */ + curpkgd = xbps_find_pkg_in_dict_by_name(transd, "unsorted_deps", pkgname); + if (curpkgd != NULL) { + prop_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &curpkgver); + rv = xbps_cmpver(pkgver, curpkgver); + if (rv == 1) { + xbps_remove_pkg_from_dict_by_name(transd, + "unsorted_deps", pkgname); + xbps_dbg_printf("%s: found pkg `%s' in transaction, replaced by `%s'.\n", + __func__, curpkgver, pkgver); + } + } /* * Overwrite package state in dictionary with same state than the * package currently uses, otherwise not-installed. @@ -61,6 +77,7 @@ store_dependency(prop_dictionary_t transd, */ if (!prop_dictionary_set_bool(repo_pkgd, "automatic-install", true)) return errno; + /* * Add the dictionary into the array. */ @@ -372,7 +389,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ curpkgd = xbps_repository_pool_find_virtualpkg(reqpkg, true); if (curpkgd == NULL) { curpkgd = xbps_repository_pool_find_pkg(reqpkg, true, - false); + true); if (curpkgd == NULL) { /* pkg not found, there was some error */ if (errno && errno != ENOENT) {