diff --git a/bin/xbps-install/main.c b/bin/xbps-install/main.c index 5a3656df2..8254bcfc7 100644 --- a/bin/xbps-install/main.c +++ b/bin/xbps-install/main.c @@ -238,8 +238,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, NULL)) != 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/bin/xbps-query/ownedby.c b/bin/xbps-query/ownedby.c index baa82c3b4..2561677fb 100644 --- a/bin/xbps-query/ownedby.c +++ b/bin/xbps-query/ownedby.c @@ -192,8 +192,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 7f3dfe0ff..0e6db2eca 100644 --- a/bin/xbps-query/search.c +++ b/bin/xbps-query/search.c @@ -225,9 +225,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; @@ -242,7 +248,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) { xbps_error_printf("Failed to initialize rpool: %s\n", strerror(rv)); return rv; diff --git a/include/xbps.h.in b/include/xbps.h.in index dd9689a1d..08747420f 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -1482,16 +1482,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. + * @return 0 on success or a negative errno otherwise. + * @retval -ENOENT There are no repositories to sync. */ -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 aa58849de..6a27e7d8f 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -59,16 +59,15 @@ 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; + 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 argument was set just process that repository */ - if (uri && strcmp(repouri, uri)) - continue; - if (xbps_repo_sync(xhp, repouri) == -1) { xbps_dbg_printf( "[rpool] `%s' failed to fetch repository data: %s\n", @@ -143,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); @@ -161,13 +160,10 @@ xbps_rpool_foreach(struct xbps_handle *xhp, SIMPLEQ_INSERT_TAIL(&rpool_queue, repo, entries); xbps_dbg_printf("[rpool] `%s' registered.\n", repouri); } - foundrepo = true; rv = (*fn)(repo, arg, &done); if (rv != 0 || done) break; } - if (!foundrepo) - rv = ENOTSUP; return rv; }