2009-11-26 07:52:50 +05:30
|
|
|
/*-
|
2011-01-18 19:14:39 +05:30
|
|
|
* Copyright (c) 2009-2011 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#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
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
/**
|
|
|
|
* @file lib/repository_pool.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
|
|
|
*/
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
struct repository_pool {
|
|
|
|
SIMPLEQ_ENTRY(repository_pool) rp_entries;
|
|
|
|
struct repository_pool_index *rpi;
|
|
|
|
};
|
|
|
|
|
|
|
|
static SIMPLEQ_HEAD(rpool_head, repository_pool) rpool_queue =
|
|
|
|
SIMPLEQ_HEAD_INITIALIZER(rpool_queue);
|
|
|
|
|
2009-11-26 07:52:50 +05:30
|
|
|
static bool repolist_initialized;
|
|
|
|
|
2011-07-28 12:55:30 +05:30
|
|
|
#define FETCH_ERROR(x) ((x == FETCH_UNAVAIL) || \
|
|
|
|
(x == FETCH_NETWORK) || \
|
|
|
|
(x == FETCH_ABORT) || \
|
|
|
|
(x == FETCH_TIMEOUT) || \
|
|
|
|
(x == FETCH_DOWN))
|
|
|
|
static int
|
|
|
|
sync_remote_repo(const char *plist, const char *repourl)
|
|
|
|
{
|
|
|
|
/* if file is there, continue */
|
|
|
|
if (access(plist, R_OK) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* file not found, fetch it */
|
|
|
|
if (xbps_repository_sync_pkg_index(repourl) == -1) {
|
|
|
|
if (FETCH_ERROR(fetchLastErrCode))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#undef FETCH_ERROR
|
2011-07-14 03:43:25 +05:30
|
|
|
|
2011-06-04 17:07:53 +05:30
|
|
|
int HIDDEN
|
2009-11-26 07:52:50 +05:30
|
|
|
xbps_repository_pool_init(void)
|
|
|
|
{
|
2011-07-27 20:43:54 +05:30
|
|
|
struct xbps_handle *xhp;
|
2009-11-26 07:52:50 +05:30
|
|
|
prop_array_t array;
|
|
|
|
prop_object_t obj;
|
2009-11-27 02:11:46 +05:30
|
|
|
prop_object_iterator_t iter = NULL;
|
2009-11-30 16:54:04 +05:30
|
|
|
struct repository_pool *rpool;
|
2009-11-27 02:11:46 +05:30
|
|
|
size_t ntotal = 0, nmissing = 0;
|
2011-06-04 17:07:53 +05:30
|
|
|
const char *repouri;
|
2009-11-26 07:52:50 +05:30
|
|
|
char *plist;
|
|
|
|
int rv = 0;
|
2011-06-04 17:07:53 +05:30
|
|
|
bool duprepo;
|
2009-11-26 07:52:50 +05:30
|
|
|
|
2011-02-21 22:12:47 +05:30
|
|
|
xhp = xbps_handle_get();
|
2011-06-04 19:21:32 +05:30
|
|
|
if (xhp->conf_dictionary == NULL)
|
|
|
|
return ENOTSUP;
|
2011-01-18 19:14:39 +05:30
|
|
|
|
2011-06-04 17:07:53 +05:30
|
|
|
if (repolist_initialized)
|
2009-11-26 07:52:50 +05:30
|
|
|
return 0;
|
|
|
|
|
2011-06-04 17:07:53 +05:30
|
|
|
array = prop_dictionary_get(xhp->conf_dictionary, "repositories");
|
2011-06-04 18:38:50 +05:30
|
|
|
if (array == NULL)
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
if (prop_array_count(array) == 0)
|
|
|
|
return ENOTSUP;
|
|
|
|
|
2009-11-26 07:52:50 +05:30
|
|
|
iter = prop_array_iterator(array);
|
|
|
|
if (iter == NULL) {
|
2009-11-27 02:11:46 +05:30
|
|
|
rv = errno;
|
|
|
|
goto out;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
/*
|
2011-06-04 17:07:53 +05:30
|
|
|
* Check that we do not register duplicate repositories.
|
2009-11-26 07:52:50 +05:30
|
|
|
*/
|
2011-06-04 17:07:53 +05:30
|
|
|
duprepo = false;
|
|
|
|
repouri = prop_string_cstring_nocopy(obj);
|
|
|
|
SIMPLEQ_FOREACH(rpool, &rpool_queue, rp_entries) {
|
|
|
|
if (strcmp(rpool->rpi->rpi_uri, repouri) == 0) {
|
|
|
|
duprepo = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (duprepo)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
plist = xbps_pkg_index_plist(repouri);
|
2009-11-26 07:52:50 +05:30
|
|
|
if (plist == NULL) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = errno;
|
2009-11-27 02:11:46 +05:30
|
|
|
goto out;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
2011-07-29 14:47:34 +05:30
|
|
|
ntotal++;
|
2011-07-28 12:55:30 +05:30
|
|
|
if (sync_remote_repo(plist, repouri) == -1) {
|
|
|
|
nmissing++;
|
|
|
|
free(plist);
|
|
|
|
continue;
|
2011-06-04 17:07:53 +05:30
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Iterate over the repository pool and add the dictionary
|
|
|
|
* for current repository into the queue.
|
|
|
|
*/
|
2009-11-26 07:52:50 +05:30
|
|
|
|
2009-11-30 16:54:04 +05:30
|
|
|
rpool = malloc(sizeof(struct repository_pool));
|
|
|
|
if (rpool == NULL) {
|
2009-11-26 07:52:50 +05:30
|
|
|
rv = errno;
|
2011-06-04 17:07:53 +05:30
|
|
|
free(plist);
|
2009-11-27 02:11:46 +05:30
|
|
|
goto out;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
rpool->rpi = malloc(sizeof(struct repository_pool_index));
|
|
|
|
if (rpool->rpi == NULL) {
|
|
|
|
rv = errno;
|
2011-06-04 17:07:53 +05:30
|
|
|
free(plist);
|
2010-01-18 04:56:50 +05:30
|
|
|
free(rpool);
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpool->rpi->rpi_uri = prop_string_cstring(obj);
|
|
|
|
if (rpool->rpi->rpi_uri == NULL) {
|
2009-11-27 02:11:46 +05:30
|
|
|
rv = errno;
|
2010-11-19 18:10:13 +05:30
|
|
|
free(rpool->rpi);
|
|
|
|
free(rpool);
|
|
|
|
free(plist);
|
2009-11-27 02:11:46 +05:30
|
|
|
goto out;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
rpool->rpi->rpi_repod =
|
|
|
|
prop_dictionary_internalize_from_zfile(plist);
|
|
|
|
if (rpool->rpi->rpi_repod == NULL) {
|
|
|
|
free(rpool->rpi->rpi_uri);
|
|
|
|
free(rpool->rpi);
|
2010-01-18 04:56:50 +05:30
|
|
|
free(rpool);
|
2009-11-26 07:52:50 +05:30
|
|
|
free(plist);
|
2009-11-27 02:11:46 +05:30
|
|
|
if (errno == ENOENT) {
|
2011-02-17 13:54:57 +05:30
|
|
|
errno = 0;
|
2011-07-29 14:47:34 +05:30
|
|
|
xbps_dbg_printf("[rpool] missing pkg-index.plist "
|
|
|
|
"for '%s' repository.\n", repouri);
|
2009-11-27 02:11:46 +05:30
|
|
|
nmissing++;
|
|
|
|
continue;
|
|
|
|
}
|
2011-02-17 13:54:57 +05:30
|
|
|
rv = errno;
|
2011-07-29 14:47:34 +05:30
|
|
|
xbps_dbg_printf("[rpool] cannot internalize plist %s: %s\n",
|
|
|
|
plist, strerror(rv));
|
2009-11-27 02:11:46 +05:30
|
|
|
goto out;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
|
|
|
free(plist);
|
2010-11-19 18:10:13 +05:30
|
|
|
xbps_dbg_printf("Registered repository '%s'\n",
|
|
|
|
rpool->rpi->rpi_uri);
|
|
|
|
SIMPLEQ_INSERT_TAIL(&rpool_queue, rpool, rp_entries);
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
|
|
|
|
2011-07-29 14:47:34 +05:30
|
|
|
if (ntotal - nmissing == 0) {
|
|
|
|
/* no repositories available, error out */
|
|
|
|
rv = ENOTSUP;
|
2009-11-27 02:11:46 +05:30
|
|
|
goto out;
|
2011-07-29 14:47:34 +05:30
|
|
|
}
|
2009-11-27 02:11:46 +05:30
|
|
|
|
2009-11-26 07:52:50 +05:30
|
|
|
repolist_initialized = true;
|
2011-07-29 14:47:34 +05:30
|
|
|
xbps_dbg_printf("[rpool] initialized ok.\n");
|
2009-11-26 07:52:50 +05:30
|
|
|
out:
|
2009-11-27 02:11:46 +05:30
|
|
|
if (iter)
|
|
|
|
prop_object_iterator_release(iter);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (rv != 0)
|
2009-11-26 07:52:50 +05:30
|
|
|
xbps_repository_pool_release();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-06-04 17:07:53 +05:30
|
|
|
void HIDDEN
|
2009-11-26 07:52:50 +05:30
|
|
|
xbps_repository_pool_release(void)
|
|
|
|
{
|
2009-11-30 16:54:04 +05:30
|
|
|
struct repository_pool *rpool;
|
2009-11-26 07:52:50 +05:30
|
|
|
|
2011-06-04 17:07:53 +05:30
|
|
|
if (!repolist_initialized)
|
2009-11-26 07:52:50 +05:30
|
|
|
return;
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
while ((rpool = SIMPLEQ_FIRST(&rpool_queue)) != NULL) {
|
|
|
|
SIMPLEQ_REMOVE(&rpool_queue, rpool, repository_pool, rp_entries);
|
2011-01-18 19:14:39 +05:30
|
|
|
xbps_dbg_printf("Unregistering repository '%s'...",
|
2010-11-19 18:10:13 +05:30
|
|
|
rpool->rpi->rpi_uri);
|
|
|
|
prop_object_release(rpool->rpi->rpi_repod);
|
|
|
|
free(rpool->rpi->rpi_uri);
|
|
|
|
free(rpool->rpi);
|
2009-11-30 16:54:04 +05:30
|
|
|
free(rpool);
|
2011-01-18 19:14:39 +05:30
|
|
|
rpool = NULL;
|
|
|
|
xbps_dbg_printf_append("done\n");
|
|
|
|
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
|
|
|
repolist_initialized = false;
|
2011-07-29 14:47:34 +05:30
|
|
|
xbps_dbg_printf("[rpool] released ok.\n");
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xbps_repository_pool_foreach(
|
|
|
|
int (*fn)(struct repository_pool_index *, void *, bool *),
|
|
|
|
void *arg)
|
|
|
|
{
|
2011-01-30 19:39:18 +05:30
|
|
|
struct repository_pool *rpool, *rpool_new;
|
2010-11-19 18:10:13 +05:30
|
|
|
int rv = 0;
|
|
|
|
bool done = false;
|
|
|
|
|
2011-01-25 08:44:33 +05:30
|
|
|
assert(fn != NULL);
|
2011-06-22 15:25:02 +05:30
|
|
|
/*
|
|
|
|
* Initialize repository pool.
|
|
|
|
*/
|
|
|
|
if ((rv = xbps_repository_pool_init()) != 0) {
|
|
|
|
if (rv == ENOTSUP) {
|
2011-07-29 14:47:34 +05:30
|
|
|
xbps_dbg_printf("[rpool] empty repository list.\n");
|
2011-06-22 15:25:02 +05:30
|
|
|
} else if (rv != ENOENT && rv != ENOTSUP) {
|
2011-07-29 14:47:34 +05:30
|
|
|
xbps_dbg_printf("[rpool] couldn't initialize: %s\n",
|
|
|
|
strerror(rv));
|
2011-06-22 15:25:02 +05:30
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
|
2011-01-30 19:39:18 +05:30
|
|
|
SIMPLEQ_FOREACH_SAFE(rpool, &rpool_queue, rp_entries, rpool_new) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = (*fn)(rpool->rpi, arg, &done);
|
|
|
|
if (rv != 0 || done)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
2011-01-18 19:14:39 +05:30
|
|
|
|
|
|
|
struct repo_pool_fpkg {
|
|
|
|
prop_dictionary_t pkgd;
|
|
|
|
const char *pattern;
|
|
|
|
bool bypattern;
|
2011-02-05 15:55:04 +05:30
|
|
|
bool pkgfound;
|
2011-01-18 19:14:39 +05:30
|
|
|
};
|
|
|
|
|
2011-02-05 15:55:04 +05:30
|
|
|
static int
|
|
|
|
repo_find_virtualpkg_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
|
|
|
{
|
|
|
|
struct repo_pool_fpkg *rpf = arg;
|
|
|
|
|
|
|
|
if (rpf->bypattern) {
|
|
|
|
rpf->pkgd =
|
2011-07-15 21:52:58 +05:30
|
|
|
xbps_find_virtualpkg_conf_in_dict_by_pattern(rpi->rpi_repod,
|
2011-02-05 15:55:04 +05:30
|
|
|
"packages", rpf->pattern);
|
|
|
|
} else {
|
|
|
|
rpf->pkgd =
|
2011-07-15 21:52:58 +05:30
|
|
|
xbps_find_virtualpkg_conf_in_dict_by_name(rpi->rpi_repod,
|
2011-02-05 15:55:04 +05:30
|
|
|
"packages", rpf->pattern);
|
|
|
|
}
|
|
|
|
if (rpf->pkgd) {
|
|
|
|
prop_dictionary_set_cstring(rpf->pkgd, "repository",
|
|
|
|
rpi->rpi_uri);
|
|
|
|
*done = true;
|
|
|
|
rpf->pkgfound = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* not found */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-18 19:14:39 +05:30
|
|
|
static int
|
|
|
|
repo_find_pkg_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
|
|
|
{
|
|
|
|
struct repo_pool_fpkg *rpf = arg;
|
|
|
|
|
|
|
|
if (rpf->bypattern) {
|
|
|
|
rpf->pkgd = xbps_find_pkg_in_dict_by_pattern(rpi->rpi_repod,
|
|
|
|
"packages", rpf->pattern);
|
2011-07-15 21:52:58 +05:30
|
|
|
/* If no pkg exists matching pattern, look for virtual packages */
|
|
|
|
if (rpf->pkgd == NULL) {
|
|
|
|
rpf->pkgd = xbps_find_virtualpkg_in_dict_by_pattern(
|
|
|
|
rpi->rpi_repod, "packages", rpf->pattern);
|
|
|
|
}
|
2011-01-18 19:14:39 +05:30
|
|
|
} else {
|
|
|
|
rpf->pkgd = xbps_find_pkg_in_dict_by_name(rpi->rpi_repod,
|
|
|
|
"packages", rpf->pattern);
|
2011-07-15 21:52:58 +05:30
|
|
|
/* If no pkg exists matching pattern, look for virtual packages */
|
|
|
|
if (rpf->pkgd == NULL) {
|
|
|
|
rpf->pkgd = xbps_find_virtualpkg_in_dict_by_name(
|
|
|
|
rpi->rpi_repod, "packages", rpf->pattern);
|
|
|
|
}
|
2011-01-18 19:14:39 +05:30
|
|
|
}
|
|
|
|
if (rpf->pkgd) {
|
|
|
|
/*
|
|
|
|
* Package dictionary found, add the "repository"
|
|
|
|
* object with the URI.
|
|
|
|
*/
|
|
|
|
prop_dictionary_set_cstring(rpf->pkgd, "repository",
|
|
|
|
rpi->rpi_uri);
|
|
|
|
*done = true;
|
2011-02-05 15:55:04 +05:30
|
|
|
rpf->pkgfound = true;
|
2011-01-18 19:14:39 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Not found */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
repo_find_best_pkg_cb(struct repository_pool_index *rpi,
|
|
|
|
void *arg,
|
|
|
|
bool *done)
|
|
|
|
{
|
|
|
|
struct repo_pool_fpkg *rpf = arg;
|
2011-07-15 21:52:58 +05:30
|
|
|
prop_dictionary_t instpkgd;
|
2011-01-18 19:14:39 +05:30
|
|
|
const char *instver, *repover;
|
|
|
|
|
|
|
|
rpf->pkgd = xbps_find_pkg_in_dict_by_name(rpi->rpi_repod,
|
|
|
|
"packages", rpf->pattern);
|
|
|
|
if (rpf->pkgd == NULL) {
|
|
|
|
if (errno && errno != ENOENT)
|
|
|
|
return errno;
|
|
|
|
|
2011-07-29 14:47:34 +05:30
|
|
|
xbps_dbg_printf("[rpool] Package '%s' not found in repository "
|
2011-01-18 19:14:39 +05:30
|
|
|
"'%s'.\n", rpf->pattern, rpi->rpi_uri);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Check if version in repository is greater than
|
|
|
|
* the version currently installed.
|
|
|
|
*/
|
|
|
|
instpkgd = xbps_find_pkg_dict_installed(rpf->pattern, false);
|
2011-02-05 15:55:04 +05:30
|
|
|
if (instpkgd == NULL)
|
|
|
|
return 0;
|
2011-01-18 19:14:39 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(instpkgd,
|
|
|
|
"version", &instver);
|
|
|
|
prop_dictionary_get_cstring_nocopy(rpf->pkgd,
|
|
|
|
"version", &repover);
|
|
|
|
prop_object_release(instpkgd);
|
|
|
|
|
2011-07-08 18:58:57 +05:30
|
|
|
if (xbps_cmpver(repover, instver) <= 0) {
|
2011-07-29 14:47:34 +05:30
|
|
|
xbps_dbg_printf("[rpool] Skipping '%s-%s' "
|
|
|
|
"(installed: %s) from repository `%s'\n",
|
|
|
|
rpf->pattern, repover, instver,
|
2011-07-08 18:58:57 +05:30
|
|
|
rpi->rpi_uri);
|
|
|
|
errno = EEXIST;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* New package version found, exit from the loop.
|
|
|
|
*/
|
2011-07-29 14:47:34 +05:30
|
|
|
xbps_dbg_printf("[rpool] Found '%s-%s' (installed: %s) "
|
2011-07-08 18:58:57 +05:30
|
|
|
"in repository '%s'.\n", rpf->pattern, repover,
|
|
|
|
instver, rpi->rpi_uri);
|
|
|
|
prop_dictionary_set_cstring(rpf->pkgd, "repository",
|
2011-01-18 19:14:39 +05:30
|
|
|
rpi->rpi_uri);
|
2011-07-08 18:58:57 +05:30
|
|
|
*done = true;
|
|
|
|
errno = 0;
|
|
|
|
rpf->pkgfound = true;
|
2011-01-18 19:14:39 +05:30
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop_dictionary_t
|
|
|
|
xbps_repository_pool_find_pkg(const char *pkg, bool bypattern, bool best)
|
|
|
|
{
|
|
|
|
struct repo_pool_fpkg *rpf;
|
|
|
|
prop_dictionary_t pkgd = NULL;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
assert(pkg != NULL);
|
|
|
|
|
|
|
|
rpf = calloc(1, sizeof(*rpf));
|
|
|
|
if (rpf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
rpf->pattern = pkg;
|
|
|
|
rpf->bypattern = bypattern;
|
|
|
|
|
2011-02-05 15:55:04 +05:30
|
|
|
if (best) {
|
|
|
|
/*
|
|
|
|
* Look for the best package version of a package name or
|
|
|
|
* pattern in all repositories.
|
|
|
|
*/
|
2011-01-18 19:14:39 +05:30
|
|
|
rv = xbps_repository_pool_foreach(repo_find_best_pkg_cb, rpf);
|
2011-02-05 15:55:04 +05:30
|
|
|
if (rv != 0) {
|
|
|
|
errno = rv;
|
|
|
|
goto out;
|
|
|
|
} else if (rpf->pkgfound == false) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Look for any virtual package set by the user matching
|
|
|
|
* the package name or pattern.
|
|
|
|
*/
|
|
|
|
rv = xbps_repository_pool_foreach(repo_find_virtualpkg_cb, rpf);
|
|
|
|
if (rv != 0) {
|
|
|
|
errno = rv;
|
|
|
|
goto out;
|
|
|
|
} else if (rpf->pkgfound == false) {
|
|
|
|
/*
|
|
|
|
* No virtual package found. Look for real package
|
|
|
|
* names or patterns instead.
|
|
|
|
*/
|
|
|
|
rv = xbps_repository_pool_foreach(repo_find_pkg_cb, rpf);
|
|
|
|
if (rv != 0) {
|
|
|
|
errno = rv;
|
|
|
|
goto out;
|
|
|
|
} else if (rpf->pkgfound == false) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-18 19:14:39 +05:30
|
|
|
pkgd = prop_dictionary_copy(rpf->pkgd);
|
|
|
|
out:
|
|
|
|
free(rpf);
|
|
|
|
|
|
|
|
return pkgd;
|
|
|
|
}
|
2011-06-01 13:07:32 +05:30
|
|
|
|
|
|
|
prop_dictionary_t
|
|
|
|
xbps_repository_pool_dictionary_metadata_plist(const char *pkgname,
|
|
|
|
const char *plistf)
|
|
|
|
{
|
|
|
|
prop_dictionary_t pkgd = NULL, plistd = NULL;
|
|
|
|
const char *repoloc;
|
|
|
|
char *url;
|
|
|
|
|
|
|
|
assert(pkgname != NULL);
|
|
|
|
assert(plistf != NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over the the repository pool and search for a plist file
|
|
|
|
* in the binary package named 'pkgname'. The plist file will be
|
|
|
|
* internalized to a proplib dictionary.
|
|
|
|
*
|
|
|
|
* The first repository that has it wins and the loop is stopped.
|
|
|
|
* This will work locally and remotely, thanks to libarchive and
|
|
|
|
* libfetch!
|
|
|
|
*/
|
|
|
|
pkgd = xbps_repository_pool_find_pkg(pkgname, false, false);
|
|
|
|
if (pkgd == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "repository", &repoloc);
|
|
|
|
url = xbps_path_from_repository_uri(pkgd, repoloc);
|
|
|
|
if (url == NULL) {
|
|
|
|
errno = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
plistd = xbps_dictionary_metadata_plist_by_url(url, plistf);
|
|
|
|
free(url);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (plistd == NULL)
|
|
|
|
errno = ENOENT;
|
|
|
|
if (pkgd)
|
|
|
|
prop_object_release(pkgd);
|
|
|
|
|
|
|
|
return plistd;
|
|
|
|
}
|