From 0b116a0f3faf6cf9d6bf937ca1242a159250accb Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 2 Aug 2014 12:11:28 +0200 Subject: [PATCH] xbps-query(8): --search --property now works with objects. For example to find a package where its binpkg file is bigger than 1GB: $ xbps-query --regex -s [0-9][0-9][0-9][0-9]MB -p filename-size --- NEWS | 4 ++++ bin/xbps-query/search.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/NEWS b/NEWS index a8e91481..c5e5736a 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ xbps-0.38 (???): + * xbps-query(8): --search --property now works with objects, i.e: + + $ xbps-query -s '' -p filename-size + * xbps-remove(8): -O/--clean-cache no longer triggers an assertion when the cache directory is empty. diff --git a/bin/xbps-query/search.c b/bin/xbps-query/search.c index aa3a0917..13002737 100644 --- a/bin/xbps-query/search.c +++ b/bin/xbps-query/search.c @@ -162,6 +162,26 @@ search_array_cb(struct xbps_handle *xhp _unused, } } } + } else if (xbps_object_type(obj2) == XBPS_TYPE_NUMBER) { + /* property is a number */ + char size[8]; + + xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); + if (xbps_humanize_number(size, xbps_number_integer_value(obj2)) == -1) + exit(EXIT_FAILURE); + + if (sd->regex) { + if (regcomp(®ex, sd->pat, REG_EXTENDED|REG_NOSUB) != 0) + return errno; + if (regexec(®ex, size, 0, 0, 0) == 0) { + printf("%s: %s (%s)\n", pkgver, size, sd->repourl); + } + regfree(®ex); + } else { + if (strcasestr(size, sd->pat)) { + printf("%s: %s (%s)\n", pkgver, size, sd->repourl); + } + } } else if (xbps_object_type(obj2) == XBPS_TYPE_BOOL) { /* property is a bool */ xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);