diff --git a/include/xbps_api.h.in b/include/xbps_api.h.in index aa140ab7..a57de359 100644 --- a/include/xbps_api.h.in +++ b/include/xbps_api.h.in @@ -56,7 +56,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.5" -#define XBPS_API_VERSION "20121119-2" +#define XBPS_API_VERSION "20121119-3" #ifndef XBPS_VERSION #define XBPS_VERSION "UNSET" @@ -749,6 +749,21 @@ prop_dictionary_t xbps_pkgdb_get_pkgd(struct xbps_handle *xhp, const char *pkg, bool bypattern); +/** + * Returns a package dictionary from master package database (pkgdb) plist, + * matching virtual pkgname or pkgver object in \a pkg. + * + * @param[in] xhp The pointer to the xbps_handle struct. + * @param[in] pkg Package name or name-version to match. + * @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, NULL otherwise. + */ +prop_dictionary_t xbps_pkgdb_get_virtualpkgd(struct xbps_handle *xhp, + const char *pkg, + bool bypattern); + /** * Returns a package dictionary from master package database (pkgdb) plist, * matching the pkgver object in \a pkg dictionary. diff --git a/lib/package_metadir.c b/lib/package_metadir.c index e6d44a2f..8ab80104 100644 --- a/lib/package_metadir.c +++ b/lib/package_metadir.c @@ -83,9 +83,9 @@ xbps_metadir_get_pkgd(struct xbps_handle *xhp, const char *name) plistf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, name); if (access(plistf, R_OK) == -1) { - pkgd = xbps_find_virtualpkg_dict_installed(xhp, name, false); + pkgd = xbps_pkgdb_get_virtualpkgd(xhp, name, false); if (pkgd == NULL) - pkgd = xbps_find_pkg_dict_installed(xhp, name, false); + pkgd = xbps_pkgdb_get_pkgd(xhp, name, false); if (pkgd != NULL) { free(plistf); diff --git a/lib/pkgdb.c b/lib/pkgdb.c index 75de7685..cee5e1a9 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -181,6 +181,40 @@ xbps_pkgdb_get_pkgd(struct xbps_handle *xhp, const char *pkg, bool bypattern) return pkgd; } +prop_dictionary_t +xbps_pkgdb_get_virtualpkgd(struct xbps_handle *xhp, + const char *vpkg, + bool bypattern) +{ + prop_dictionary_t pkgd = NULL; + + if (xbps_pkgdb_init(xhp) != 0) + return NULL; + + if (bypattern) { + /* first return vpkg from matching a conf file */ + pkgd = xbps_find_virtualpkg_conf_in_array_by_pattern(xhp, + xhp->pkgdb, vpkg); + if (pkgd != NULL) + return pkgd; + + /* ... otherwise the first one in array */ + pkgd = xbps_find_virtualpkg_in_array_by_pattern(xhp, + xhp->pkgdb, vpkg); + } else { + /* first return vpkg from matching a conf file */ + pkgd = xbps_find_virtualpkg_conf_in_array_by_name(xhp, + xhp->pkgdb, vpkg); + if (pkgd != NULL) + return pkgd; + + pkgd = xbps_find_virtualpkg_in_array_by_name(xhp, + xhp->pkgdb, vpkg); + } + + return pkgd; +} + prop_dictionary_t xbps_pkgdb_get_pkgd_by_pkgver(struct xbps_handle *xhp, const char *pkgver) {