2009-11-26 07:52:50 +05:30
|
|
|
/*-
|
2013-03-05 08:38:42 +05:30
|
|
|
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
2009-11-26 07:52:50 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2011-11-08 00:58:35 +05:30
|
|
|
#include <sys/utsname.h>
|
2009-11-26 07:52:50 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
2012-01-15 21:53:50 +05:30
|
|
|
#include <libgen.h>
|
2009-11-26 07:52:50 +05:30
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2010-11-13 07:48:58 +05:30
|
|
|
#include "xbps_api_impl.h"
|
2009-11-26 07:52:50 +05:30
|
|
|
|
2013-12-16 13:19:33 +05:30
|
|
|
static SIMPLEQ_HEAD(rpool_head, xbps_repo) rpool_queue =
|
2013-06-10 13:58:39 +05:30
|
|
|
SIMPLEQ_HEAD_INITIALIZER(rpool_queue);
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
/**
|
2012-12-19 05:31:27 +05:30
|
|
|
* @file lib/rpool.c
|
2011-01-18 19:14:39 +05:30
|
|
|
* @brief Repository pool routines
|
|
|
|
* @defgroup repopool Repository pool functions
|
2010-01-21 07:40:19 +05:30
|
|
|
*/
|
|
|
|
|
2011-11-11 03:44:50 +05:30
|
|
|
int
|
2013-06-10 13:58:39 +05:30
|
|
|
xbps_rpool_sync(struct xbps_handle *xhp, const char *uri)
|
2011-11-11 03:44:50 +05:30
|
|
|
{
|
|
|
|
const char *repouri;
|
|
|
|
|
2013-09-18 20:15:05 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) {
|
|
|
|
xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri);
|
2012-06-01 18:32:06 +05:30
|
|
|
/* If argument was set just process that repository */
|
|
|
|
if (uri && strcmp(repouri, uri))
|
2012-01-15 18:54:44 +05:30
|
|
|
continue;
|
2012-11-07 15:07:58 +05:30
|
|
|
|
2013-06-10 13:58:39 +05:30
|
|
|
if (xbps_repo_sync(xhp, repouri) == -1) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp,
|
2013-06-10 13:58:39 +05:30
|
|
|
"[rpool] `%s' failed to fetch repository data: %s\n",
|
|
|
|
repouri, fetchLastErrCode == 0 ? strerror(errno) :
|
2012-06-01 18:32:06 +05:30
|
|
|
xbps_fetch_error_string());
|
2011-11-11 03:44:50 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-06-01 19:34:47 +05:30
|
|
|
return 0;
|
2011-11-11 03:44:50 +05:30
|
|
|
}
|
|
|
|
|
2013-12-24 15:13:55 +05:30
|
|
|
struct xbps_repo *
|
|
|
|
xbps_rpool_get_repo(const char *url)
|
|
|
|
{
|
|
|
|
struct xbps_repo *repo;
|
|
|
|
|
|
|
|
SIMPLEQ_FOREACH(repo, &rpool_queue, entries)
|
|
|
|
if (strcmp(url, repo->uri) == 0)
|
|
|
|
return repo;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
int
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_rpool_foreach(struct xbps_handle *xhp,
|
2013-10-05 15:08:04 +05:30
|
|
|
int (*fn)(struct xbps_repo *, void *, bool *),
|
|
|
|
void *arg)
|
2010-11-19 18:10:13 +05:30
|
|
|
{
|
2013-12-16 13:19:33 +05:30
|
|
|
struct xbps_repo *repo;
|
2013-12-24 15:13:55 +05:30
|
|
|
const char *repouri;
|
2010-11-19 18:10:13 +05:30
|
|
|
int rv = 0;
|
2013-12-24 15:13:55 +05:30
|
|
|
bool foundrepo = false, done = false;
|
2010-11-19 18:10:13 +05:30
|
|
|
|
2011-01-25 08:44:33 +05:30
|
|
|
assert(fn != NULL);
|
2013-12-24 15:13:55 +05:30
|
|
|
|
|
|
|
for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) {
|
|
|
|
xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri);
|
|
|
|
repo = xbps_rpool_get_repo(repouri);
|
|
|
|
if (!repo) {
|
|
|
|
repo = xbps_repo_open(xhp, repouri);
|
|
|
|
SIMPLEQ_INSERT_TAIL(&rpool_queue, repo, entries);
|
|
|
|
xbps_dbg_printf(xhp, "[rpool] `%s' registered.\n", repouri);
|
2011-06-22 15:25:02 +05:30
|
|
|
}
|
2013-12-24 15:13:55 +05:30
|
|
|
foundrepo = true;
|
2013-12-16 13:19:33 +05:30
|
|
|
rv = (*fn)(repo, arg, &done);
|
2012-02-01 07:00:23 +05:30
|
|
|
if (rv != 0 || done)
|
2010-11-19 18:10:13 +05:30
|
|
|
break;
|
|
|
|
}
|
2013-12-24 15:13:55 +05:30
|
|
|
if (!foundrepo)
|
|
|
|
rv = ENOTSUP;
|
2010-11-19 18:10:13 +05:30
|
|
|
|
|
|
|
return rv;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|