From b2f5afd02eda98da10f72a3b42e8e4fd345efb25 Mon Sep 17 00:00:00 2001 From: Duncaen Date: Sat, 15 Jun 2019 19:15:22 +0200 Subject: [PATCH] lib/repo: add xbps_repo_remove and use it in xbps_rpool_foreach https://github.com/void-linux/xbps/issues/3 --- include/xbps.h.in | 12 +++++++++++- lib/repo.c | 23 +++++++++++++++++++++++ lib/rpool.c | 4 +++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/xbps.h.in b/include/xbps.h.in index 0cb01723..6cd53284 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -48,7 +48,7 @@ * * This header documents the full API for the XBPS Library. */ -#define XBPS_API_VERSION "20190614" +#define XBPS_API_VERSION "20190615" #ifndef XBPS_VERSION #define XBPS_VERSION "UNSET" @@ -1476,6 +1476,16 @@ xbps_dictionary_t xbps_rpool_get_pkg_plist(struct xbps_handle *xhp, */ bool xbps_repo_store(struct xbps_handle *xhp, const char *url); +/** + * Removes repository \a url from the repository pool. + * + * @param[in] xhp Pointer to the xbps_handle struct. + * @param[in] uri Repository URI to remove. + * + * @return True on success, false otherwise. + */ +bool xbps_repo_remove(struct xbps_handle *xhp, const char *url); + /** * Creates a lock for a local repository to obtain exclusive access (write). * diff --git a/lib/repo.c b/lib/repo.c index dc718ffe..18363046 100644 --- a/lib/repo.c +++ b/lib/repo.c @@ -294,6 +294,29 @@ xbps_repo_store(struct xbps_handle *xhp, const char *repo) return false; } +bool +xbps_repo_remove(struct xbps_handle *xhp, const char *repo) +{ + char *url; + bool rv = false; + + assert(xhp); + assert(repo); + + if (xhp->repositories == NULL) + return false; + + url = strdup(repo); + if (xbps_remove_string_from_array(xhp->repositories, repo)) { + if (url) + xbps_dbg_printf(xhp, "[repo] `%s' removed\n", url); + rv = true; + } + free(url); + + return rv; +} + struct xbps_repo * xbps_repo_stage_open(struct xbps_handle *xhp, const char *url) { diff --git a/lib/rpool.c b/lib/rpool.c index 94af7298..804f31b9 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -148,8 +148,10 @@ xbps_rpool_foreach(struct xbps_handle *xhp, xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri); if ((repo = xbps_rpool_get_repo(repouri)) == NULL) { repo = xbps_repo_open(xhp, repouri); - if (!repo) + if (!repo) { + xbps_repo_remove(xhp, repouri); continue; + } SIMPLEQ_INSERT_TAIL(&rpool_queue, repo, entries); xbps_dbg_printf(xhp, "[rpool] `%s' registered.\n", repouri); }