From ce4fd6a63cd88b0e7a2e0e6df6cfa58cadacb35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= Date: Sat, 4 Dec 2021 23:27:02 +0100 Subject: [PATCH] xbps-query: list unavailable repositories in -L mode --- bin/xbps-query/list.c | 29 ++++++++++++++++++++--------- tests/xbps/xbps-query/Kyuafile | 1 + tests/xbps/xbps-query/Makefile | 2 +- tests/xbps/xbps-query/list_test.sh | 28 ++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 tests/xbps/xbps-query/list_test.sh diff --git a/bin/xbps-query/list.c b/bin/xbps-query/list.c index 6deaf1a1..76b19c3f 100644 --- a/bin/xbps-query/list.c +++ b/bin/xbps-query/list.c @@ -23,6 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -178,8 +179,8 @@ list_pkgs_pkgdb(struct xbps_handle *xhp) return xbps_pkgdb_foreach_cb(xhp, list_pkgs_in_dict, &lpc); } -static int -repo_list_uri_cb(struct xbps_repo *repo, void *arg UNUSED, bool *done UNUSED) +static void +repo_list_uri(struct xbps_repo *repo) { const char *signedby = NULL; uint16_t pubkeysize = 0; @@ -204,19 +205,29 @@ repo_list_uri_cb(struct xbps_repo *repo, void *arg UNUSED, bool *done UNUSED) if (hexfp) free(hexfp); } - return 0; +} + +static void +repo_list_uri_err(const char *repouri) +{ + printf("%5zd %s (RSA maybe-signed)\n", (ssize_t) -1, repouri); } int repo_list(struct xbps_handle *xhp) { - int rv; + struct xbps_repo *repo = NULL; + const char *repouri = NULL; - rv = xbps_rpool_foreach(xhp, repo_list_uri_cb, NULL); - if (rv != 0 && rv != ENOTSUP) { - fprintf(stderr, "Failed to initialize rpool: %s\n", - strerror(rv)); - return rv; + for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) { + xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri); + repo = xbps_repo_open(xhp, repouri); + if (repo) { + repo_list_uri(repo); + xbps_repo_close(repo); + } else { + repo_list_uri_err(repouri); + } } return 0; } diff --git a/tests/xbps/xbps-query/Kyuafile b/tests/xbps/xbps-query/Kyuafile index 3a3dbfe0..e0fbada3 100644 --- a/tests/xbps/xbps-query/Kyuafile +++ b/tests/xbps/xbps-query/Kyuafile @@ -2,5 +2,6 @@ syntax("kyuafile", 1) test_suite("xbps-query") atf_test_program{name="ignore_repos_test"} +atf_test_program{name="list_test"} atf_test_program{name="remote_test"} atf_test_program{name="query_test"} diff --git a/tests/xbps/xbps-query/Makefile b/tests/xbps/xbps-query/Makefile index 7c0b8294..b6db392d 100644 --- a/tests/xbps/xbps-query/Makefile +++ b/tests/xbps/xbps-query/Makefile @@ -1,7 +1,7 @@ TOPDIR = ../../.. -include $(TOPDIR)/config.mk -TESTSHELL = ignore_repos_test remote_test query_test +TESTSHELL = ignore_repos_test list_test remote_test query_test TESTSSUBDIR = xbps/xbps-query EXTRA_FILES = Kyuafile diff --git a/tests/xbps/xbps-query/list_test.sh b/tests/xbps/xbps-query/list_test.sh new file mode 100644 index 00000000..528574ae --- /dev/null +++ b/tests/xbps/xbps-query/list_test.sh @@ -0,0 +1,28 @@ +#! /usr/bin/env atf-sh +# Test that xbps-query(1) list modes work as expected + +atf_test_case list_repos + +list_repos_head() { + atf_set "descr" "xbps-query(1) -L" +} + +list_repos_body() { + mkdir -p some_repo pkg_A/bin + touch pkg_A/bin/file + cd some_repo + xbps-create -A noarch -n foo-1.0_1 -s "foo pkg" ../pkg_A + atf_check_equal $? 0 + xbps-create -A noarch -n baz-1.0_1 -s "baz pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + rm -f *.xbps + cd .. + output="$(xbps-query -C empty.conf -i --repository=some_repo --repository=vanished_repo -L | tr -d '\n')" + atf_check_equal "$output" " 2 ${PWD}/some_repo (RSA unsigned) -1 vanished_repo (RSA maybe-signed)" +} + +atf_init_test_cases() { + atf_add_test_case list_repos +}