From 732ce45b86608cc027cdb949996697ed473bdaac Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 5 Apr 2012 10:57:15 +0200 Subject: [PATCH] libxbps: new function xbps_pkgdb_get_pkgd_by_pkgver(). Finds a pkg dictionary in pkgdb by matching its pkgver object. --- include/xbps_api.h | 16 ++++++++++++++-- lib/pkgdb.c | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/xbps_api.h b/include/xbps_api.h index 791670f0..2a39fdb8 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 "20120404" +#define XBPS_API_VERSION "20120405" #define XBPS_VERSION "0.15" /** @@ -708,12 +708,24 @@ int xbps_pkgdb_foreach_reverse_cb( * @param[in] bypattern If false \a pkg must be a pkgname, otherwise a * package pattern, i.e `foo>=0' or `foo<1'. * - * @return The matching proplib package dictionary from kgdb copied + * @return The matching proplib package dictionary from pkgdb copied * with \a prop_dictionary_copy() so it must be released when not required * anymore with prop_object_release(). NULL otherwise. */ prop_dictionary_t xbps_pkgdb_get_pkgd(const char *pkg, bool bypattern); +/** + * Returns a package dictionary from master package database (pkgdb) plist, + * matching the pkgver object in \a pkg dictionary. + * + * @param[in] pkgver Package name-version to match, i.e 'foo-1.0'. + * + * @return The matching proplib package dictionary from pkgdb copied + * with \a prop_dictionary_copy() so it must be released when not required + * anymore with prop_object_release(). NULL otherwise. + */ +prop_dictionary_t xbps_pkgdb_get_pkgd_by_pkgver(const char *pkgver); + /** * Removes a package dictionary from master package database (pkgdb) plist, * matching pkgname or pkgver object in \a pkg. diff --git a/lib/pkgdb.c b/lib/pkgdb.c index 8aeb924d..0c405a75 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -189,6 +189,22 @@ xbps_pkgdb_get_pkgd(const char *pkg, bool bypattern) return NULL; } +prop_dictionary_t +xbps_pkgdb_get_pkgd_by_pkgver(const char *pkgver) +{ + struct xbps_handle *xhp = xbps_handle_get(); + prop_dictionary_t pkgd = NULL; + + if (xbps_pkgdb_init(xhp) != 0) + return NULL; + + pkgd = xbps_find_pkg_in_array_by_pkgver(xhp->pkgdb, pkgver); + if (pkgd != NULL) + return prop_dictionary_copy(pkgd); + + return NULL; +} + bool xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush) {