26#include <sys/utsname.h>
34#include "xbps_api_impl.h"
39 xbps_dictionary_t pkgd;
41 const char *bestpkgver;
52static SIMPLEQ_HEAD(rpool_head,
xbps_repo) rpool_queue =
53 SIMPLEQ_HEAD_INITIALIZER(rpool_queue);
64 const char *repouri = NULL;
66 for (
unsigned int i = 0; i < xbps_array_count(xhp->
repositories); i++) {
67 xbps_array_get_cstring_nocopy(xhp->
repositories, i, &repouri);
69 if (uri && strcmp(repouri, uri))
72 if (xbps_repo_sync(xhp, repouri) == -1) {
74 "[rpool] `%s' failed to fetch repository data: %s\n",
75 repouri, fetchLastErrCode == 0 ? strerror(errno) :
87 const char *repouri = NULL;
89 if (SIMPLEQ_EMPTY(&rpool_queue)) {
91 for (
unsigned int i = 0; i < xbps_array_count(
xhp->
repositories); i++) {
93 if (strcmp(repouri, url))
100 SIMPLEQ_INSERT_TAIL(&rpool_queue, repo, entries);
101 xbps_dbg_printf(
"[rpool] `%s' registered.\n", repouri);
104 SIMPLEQ_FOREACH(repo, &rpool_queue, entries)
105 if (strcmp(url, repo->
uri) == 0)
116 SIMPLEQ_FOREACH(repo, &rpool_queue, entries)
117 if (strcmp(url, repo->
uri) == 0)
128 while ((repo = SIMPLEQ_FIRST(&rpool_queue))) {
129 SIMPLEQ_REMOVE(&rpool_queue, repo,
xbps_repo, entries);
140 int (*fn)(
struct xbps_repo *,
void *,
bool *),
144 const char *repouri = NULL;
146 bool foundrepo =
false, done =
false;
152 for (
unsigned int i = n; i < xbps_array_count(
xhp->
repositories); i++, n++) {
154 xbps_dbg_printf(
"[rpool] checking `%s' at index %u\n", repouri, n);
161 SIMPLEQ_INSERT_TAIL(&rpool_queue, repo, entries);
162 xbps_dbg_printf(
"[rpool] `%s' registered.\n", repouri);
165 rv = (*fn)(repo, arg, &done);
176find_virtualpkg_cb(
struct xbps_repo *repo,
void *arg,
bool *done)
178 struct rpool_fpkg *rpf = arg;
191find_pkg_cb(
struct xbps_repo *repo,
void *arg,
bool *done)
193 struct rpool_fpkg *rpf = arg;
206find_pkg_revdeps_cb(
struct xbps_repo *repo,
void *arg,
bool *done UNUSED)
208 struct rpool_fpkg *rpf = arg;
209 xbps_array_t revdeps = NULL;
210 const char *pkgver = NULL;
213 if (xbps_array_count(revdeps)) {
215 if (rpf->revdeps == NULL)
216 rpf->revdeps = xbps_array_create();
217 for (
unsigned int i = 0; i < xbps_array_count(revdeps); i++) {
218 xbps_array_get_cstring_nocopy(revdeps, i, &pkgver);
219 xbps_array_add_cstring_nocopy(rpf->revdeps, pkgver);
221 xbps_object_release(revdeps);
227find_best_pkg_cb(
struct xbps_repo *repo,
void *arg,
bool *done UNUSED)
229 struct rpool_fpkg *rpf = arg;
230 xbps_dictionary_t pkgd;
231 const char *repopkgver = NULL;
235 if (errno && errno != ENOENT)
238 xbps_dbg_printf(
"[rpool] Package '%s' not found in repository"
239 " '%s'.\n", rpf->pattern, repo->
uri);
242 xbps_dictionary_get_cstring_nocopy(pkgd,
243 "pkgver", &repopkgver);
244 if (rpf->bestpkgver == NULL) {
245 xbps_dbg_printf(
"[rpool] Found match '%s' (%s).\n",
246 repopkgver, repo->
uri);
248 rpf->bestpkgver = repopkgver;
255 if (
xbps_cmpver(repopkgver, rpf->bestpkgver) == 1) {
256 xbps_dbg_printf(
"[rpool] Found best match '%s' (%s).\n",
257 repopkgver, repo->
uri);
259 rpf->bestpkgver = repopkgver;
267 pkg_repo_type_t type)
269 struct rpool_fpkg rpf;
278 rpf.bestpkgver = NULL;
310 if (type == REVDEPS_PKG) {
311 if (rpf.revdeps == NULL)
316 if (rpf.pkgd == NULL)
325 return repo_find_pkg(xhp, pkg, VIRTUAL_PKG);
331 if (xhp->
flags & XBPS_FLAG_BESTMATCH)
332 return repo_find_pkg(xhp, pkg, BEST_PKG);
334 return repo_find_pkg(xhp, pkg, REAL_PKG);
340 return repo_find_pkg(xhp, pkg, REVDEPS_PKG);
346 return xbps_get_pkg_fulldeptree(xhp, pkg,
true);
const char * xbps_fetch_error_string(void)
xbps_array_t repositories
Generic XBPS structure handler for initialization.
xbps_dictionary_t xbps_repo_get_pkg(struct xbps_repo *repo, const char *pkg)
struct xbps_repo * xbps_repo_open(struct xbps_handle *xhp, const char *uri)
void xbps_repo_release(struct xbps_repo *repo)
bool xbps_repo_remove(struct xbps_handle *xhp, const char *url)
xbps_dictionary_t xbps_repo_get_virtualpkg(struct xbps_repo *repo, const char *pkg)
xbps_array_t xbps_repo_get_pkg_revdeps(struct xbps_repo *repo, const char *pkg)
int xbps_rpool_foreach(struct xbps_handle *xhp, int(*fn)(struct xbps_repo *, void *, bool *), void *arg)
struct xbps_repo * xbps_rpool_get_repo(const char *url)
xbps_dictionary_t xbps_rpool_get_virtualpkg(struct xbps_handle *xhp, const char *pkg)
xbps_dictionary_t xbps_rpool_get_pkg(struct xbps_handle *xhp, const char *pkg)
xbps_array_t xbps_rpool_get_pkg_fulldeptree(struct xbps_handle *xhp, const char *pkg)
xbps_array_t xbps_rpool_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
int xbps_rpool_sync(struct xbps_handle *xhp, const char *uri)
int xbps_cmpver(const char *pkg1, const char *pkg2)