From 5db7f647fd6f35bfa908a25d2b8e894f90bc8091 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Wed, 29 Dec 2021 13:44:33 +0100 Subject: [PATCH 1/4] lib/rpool.c: remove ENOTSUP error from xbps_rpool_foreach This error is already ignored by most callers and where it wasn't it masked the real error of packages simply not being found without repositories. Fixes #454. --- bin/xbps-query/list.c | 2 +- bin/xbps-query/search.c | 2 +- lib/rpool.c | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bin/xbps-query/list.c b/bin/xbps-query/list.c index 6deaf1a1e..fc7d4906a 100644 --- a/bin/xbps-query/list.c +++ b/bin/xbps-query/list.c @@ -213,7 +213,7 @@ repo_list(struct xbps_handle *xhp) int rv; rv = xbps_rpool_foreach(xhp, repo_list_uri_cb, NULL); - if (rv != 0 && rv != ENOTSUP) { + if (rv != 0) { fprintf(stderr, "Failed to initialize rpool: %s\n", strerror(rv)); return rv; diff --git a/bin/xbps-query/search.c b/bin/xbps-query/search.c index bfc1a3962..b39caadb5 100644 --- a/bin/xbps-query/search.c +++ b/bin/xbps-query/search.c @@ -246,7 +246,7 @@ search(struct xbps_handle *xhp, bool repo_mode, const char *pat, const char *pro if (repo_mode) { rv = xbps_rpool_foreach(xhp, search_repo_cb, &sd); - if (rv != 0 && rv != ENOTSUP) { + if (rv != 0) { fprintf(stderr, "Failed to initialize rpool: %s\n", strerror(rv)); return rv; diff --git a/lib/rpool.c b/lib/rpool.c index 70e571262..8b8b05322 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -142,7 +142,7 @@ xbps_rpool_foreach(struct xbps_handle *xhp, struct xbps_repo *repo = NULL; const char *repouri = NULL; int rv = 0; - bool foundrepo = false, done = false; + bool done = false; unsigned int n = 0; assert(fn != NULL); @@ -160,13 +160,10 @@ xbps_rpool_foreach(struct xbps_handle *xhp, SIMPLEQ_INSERT_TAIL(&rpool_queue, repo, entries); xbps_dbg_printf(xhp, "[rpool] `%s' registered.\n", repouri); } - foundrepo = true; rv = (*fn)(repo, arg, &done); if (rv != 0 || done) break; } - if (!foundrepo) - rv = ENOTSUP; return rv; } From 7a62e6731163598efcad7179be702f624c482dfc Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Wed, 29 Dec 2021 15:21:34 +0100 Subject: [PATCH 2/4] lib/rpool.c: remove uri parameter from xbps_rpool_sync This parameter is unused and does not really belong belong in the repository pool synchronization function, if there needs to be a way to sync only specific repositories, a new function should be created for that purposed. --- bin/xbps-install/main.c | 2 +- include/xbps.h.in | 6 ++---- lib/rpool.c | 6 +----- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/bin/xbps-install/main.c b/bin/xbps-install/main.c index c626d407b..d01e2f0e0 100644 --- a/bin/xbps-install/main.c +++ b/bin/xbps-install/main.c @@ -233,7 +233,7 @@ main(int argc, char **argv) /* Sync remote repository data and import keys from remote repos */ if (syncf && !drun) { - if ((rv = xbps_rpool_sync(&xh, NULL)) != 0) + if ((rv = xbps_rpool_sync(&xh)) != 0) exit(rv); rv = xbps_rpool_foreach(&xh, repo_import_key_cb, NULL); if (rv != 0) diff --git a/include/xbps.h.in b/include/xbps.h.in index 23f73b213..9f359a02e 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -1458,16 +1458,14 @@ void xbps_rpool_release(struct xbps_handle *xhp); /** * Synchronizes repository data for all remote repositories - * as specified in the configuration file or if \a uri argument is - * set, just sync for that repository. + * as specified in the configuration file. * * @param[in] xhp Pointer to the xbps_handle struct. - * @param[in] uri Repository URI to match for sync (optional). * * @return 0 on success, ENOTSUP if no repositories were found in * the configuration file. */ -int xbps_rpool_sync(struct xbps_handle *xhp, const char *uri); +int xbps_rpool_sync(struct xbps_handle *xhp); /** * Iterates over the repository pool and executes the \a fn function diff --git a/lib/rpool.c b/lib/rpool.c index 8b8b05322..503cbe264 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -58,16 +58,12 @@ static SIMPLEQ_HEAD(rpool_head, xbps_repo) rpool_queue = */ int -xbps_rpool_sync(struct xbps_handle *xhp, const char *uri) +xbps_rpool_sync(struct xbps_handle *xhp) { const char *repouri = NULL; for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) { xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri); - /* If argument was set just process that repository */ - if (uri && strcmp(repouri, uri)) - continue; - if (xbps_repo_sync(xhp, repouri) == -1) { xbps_dbg_printf(xhp, "[rpool] `%s' failed to fetch repository data: %s\n", From f999c862b988e29cdc3d5ebe56e19c89878b8d87 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Wed, 29 Dec 2021 15:34:01 +0100 Subject: [PATCH 3/4] lib/rpool.c: xbps_rpool_sync: return error if there are no repos --- bin/xbps-install/main.c | 7 +++++-- include/xbps.h.in | 3 ++- lib/rpool.c | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/xbps-install/main.c b/bin/xbps-install/main.c index d01e2f0e0..3fc0a4393 100644 --- a/bin/xbps-install/main.c +++ b/bin/xbps-install/main.c @@ -233,8 +233,11 @@ main(int argc, char **argv) /* Sync remote repository data and import keys from remote repos */ if (syncf && !drun) { - if ((rv = xbps_rpool_sync(&xh)) != 0) - exit(rv); + if ((rv = xbps_rpool_sync(&xh)) < 0) { + fprintf(stderr, "Failed to sync repository pool: %s\n", + strerror(-rv)); + exit(-rv); + } rv = xbps_rpool_foreach(&xh, repo_import_key_cb, NULL); if (rv != 0) exit(rv); diff --git a/include/xbps.h.in b/include/xbps.h.in index 9f359a02e..375141c1a 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -1462,8 +1462,9 @@ void xbps_rpool_release(struct xbps_handle *xhp); * * @param[in] xhp Pointer to the xbps_handle struct. * - * @return 0 on success, ENOTSUP if no repositories were found in + * @return 0 on success or a negative errno otherwise. * the configuration file. + * @retval -ENOENT There are no repositories to sync. */ int xbps_rpool_sync(struct xbps_handle *xhp); diff --git a/lib/rpool.c b/lib/rpool.c index 503cbe264..167afd8ba 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -62,6 +62,9 @@ xbps_rpool_sync(struct xbps_handle *xhp) { const char *repouri = NULL; + if (xbps_array_count(xhp->repositories) == 0) + return -ENOENT; + for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) { xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri); if (xbps_repo_sync(xhp, repouri) == -1) { From b37b262bea4f3b7ce13417b326423f8087912ed8 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Wed, 29 Dec 2021 15:56:45 +0100 Subject: [PATCH 4/4] bin/xbps-query: actually report regex errors --- bin/xbps-query/ownedby.c | 7 ++++++- bin/xbps-query/search.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bin/xbps-query/ownedby.c b/bin/xbps-query/ownedby.c index 1b95d3612..a2a5acfe6 100644 --- a/bin/xbps-query/ownedby.c +++ b/bin/xbps-query/ownedby.c @@ -188,8 +188,13 @@ ownedby(struct xbps_handle *xhp, const char *pat, bool repo, bool regex) if (regex) { ffd.rematch = true; - if (regcomp(&ffd.regex, ffd.pat, REG_EXTENDED|REG_NOSUB|REG_ICASE) != 0) + rv = regcomp(&ffd.regex, ffd.pat, REG_EXTENDED|REG_NOSUB|REG_ICASE); + if (rv != 0) { + char errbuf[256]; + regerror(rv, &ffd.regex, errbuf, sizeof(errbuf)); + fprintf(stderr, "Failed to compile pattern: %s\n", errbuf); return EINVAL; + } } if (repo) rv = xbps_rpool_foreach(xhp, repo_ownedby_cb, &ffd); diff --git a/bin/xbps-query/search.c b/bin/xbps-query/search.c index b39caadb5..85b3411ea 100644 --- a/bin/xbps-query/search.c +++ b/bin/xbps-query/search.c @@ -229,9 +229,15 @@ search(struct xbps_handle *xhp, bool repo_mode, const char *pat, const char *pro sd.regex = regex; if (regex) { - if (regcomp(&sd.regexp, pat, REG_EXTENDED|REG_NOSUB|REG_ICASE) != 0) - return errno; + rv = regcomp(&sd.regexp, pat, REG_EXTENDED|REG_NOSUB|REG_ICASE); + if (rv != 0) { + char errbuf[256]; + regerror(rv, &sd.regexp, errbuf, sizeof(errbuf)); + fprintf(stderr, "Failed to compile pattern: %s\n", errbuf); + return EINVAL; + } } + sd.repo_mode = repo_mode; sd.pat = pat; sd.prop = prop;