From 18204aeac1cecb1ddb74a779727a68d2892971f5 Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Mon, 22 Sep 2014 21:22:05 +0200 Subject: [PATCH] lib/util.c: add function which tests if a given pkgver is reverted by a given pkg. --- include/xbps.h.in | 13 +++++++++++++ lib/util.c | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/xbps.h.in b/include/xbps.h.in index f5a1a8fb..32e0e824 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -1835,6 +1835,19 @@ bool xbps_pkg_arch_match(struct xbps_handle *xhp, */ int xbps_humanize_number(char *buf, int64_t bytes); +/** + * Tests if pkgver is reverted by pkg + * + * The package version is defined by: + * ${VERSION}_${REVISION}. + * + * @param[in] pkgver a package version string + * @param[in] pkg a package which is a candidate to revert pkgver. + * + * @return 1 if pkg reverts pkgver, 0 otherwise. + */ +int xbps_pkgver_is_reverted(const char *pkgver, xbps_dictionary_t pkg); + /** * Compares package version strings. * diff --git a/lib/util.c b/lib/util.c index 11ea33b1..8d476f35 100644 --- a/lib/util.c +++ b/lib/util.c @@ -425,3 +425,25 @@ xbps_humanize_number(char *buf, int64_t bytes) return humanize_number(buf, 7, bytes, "B", HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE); } + +/* + * Check if pkg is explicitly marked to replace a specific installed version. + */ +int +xbps_pkgver_is_reverted(const char *pkgver, xbps_dictionary_t pkg) { + unsigned int i; + xbps_array_t reverts; + const char *revertver; + + if ((reverts = xbps_dictionary_get(pkg, "reverts")) == NULL) + return 0; + + for (i = 0; i < xbps_array_count(reverts); i++) { + xbps_array_get_cstring_nocopy(reverts, i, &revertver); + if (strcmp(pkgver, revertver) == 0) { + return 1; + } + } + + return 0; +}