Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/rpool.c: remove ENOTSUP error from xbps_rpool_foreach #456

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions bin/xbps-install/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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);
Expand Down
2 changes: 1 addition & 1 deletion bin/xbps-query/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion bin/xbps-query/ownedby.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions bin/xbps-query/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -246,7 +252,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;
Expand Down
9 changes: 4 additions & 5 deletions include/xbps.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1458,16 +1458,15 @@ 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
* @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, const char *uri);
int xbps_rpool_sync(struct xbps_handle *xhp);

/**
* Iterates over the repository pool and executes the \a fn function
Expand Down
14 changes: 5 additions & 9 deletions lib/rpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,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(xhp,
"[rpool] `%s' failed to fetch repository data: %s\n",
Expand Down Expand Up @@ -142,7 +141,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);
Expand All @@ -160,13 +159,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;
}
Expand Down