2009-11-26 07:52:50 +05:30
|
|
|
/*-
|
|
|
|
* Copyright (c) 2009 Juan Romero Pardines.
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include <xbps_api.h>
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
/**
|
|
|
|
* @file lib/repository_pool.c
|
|
|
|
* @brief Repository pool init/fini routines
|
|
|
|
* @defgroup repopool Repository pool init/fini functions
|
|
|
|
*/
|
|
|
|
|
2009-11-26 07:52:50 +05:30
|
|
|
static size_t repolist_refcnt;
|
|
|
|
static bool repolist_initialized;
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2009-11-26 07:52:50 +05:30
|
|
|
xbps_repository_pool_init(void)
|
|
|
|
{
|
|
|
|
prop_dictionary_t dict = NULL;
|
|
|
|
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;
|
2009-11-26 07:52:50 +05:30
|
|
|
char *plist;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
if (repolist_initialized) {
|
|
|
|
repolist_refcnt++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
SIMPLEQ_INIT(&rp_queue);
|
2009-11-26 07:52:50 +05:30
|
|
|
|
|
|
|
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(),
|
|
|
|
XBPS_META_PATH, XBPS_REPOLIST);
|
|
|
|
if (plist == NULL) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-04-20 17:52:38 +05:30
|
|
|
dict = prop_dictionary_internalize_from_zfile(plist);
|
2009-11-26 07:52:50 +05:30
|
|
|
if (dict == NULL) {
|
|
|
|
free(plist);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
free(plist);
|
|
|
|
|
|
|
|
array = prop_dictionary_get(dict, "repository-list");
|
|
|
|
if (array == NULL) {
|
2009-11-27 02:11:46 +05:30
|
|
|
rv = errno;
|
|
|
|
goto out;
|
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) {
|
2009-11-27 02:11:46 +05:30
|
|
|
ntotal++;
|
2009-11-26 07:52:50 +05:30
|
|
|
/*
|
|
|
|
* Iterate over the repository pool and add the dictionary
|
|
|
|
* for current repository into the queue.
|
|
|
|
*/
|
|
|
|
plist =
|
|
|
|
xbps_get_pkg_index_plist(prop_string_cstring_nocopy(obj));
|
|
|
|
if (plist == NULL) {
|
|
|
|
rv = EINVAL;
|
2009-11-27 02:11:46 +05:30
|
|
|
goto out;
|
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;
|
2009-11-27 02:11:46 +05:30
|
|
|
goto out;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
|
|
|
|
2009-11-30 16:54:04 +05:30
|
|
|
rpool->rp_uri = prop_string_cstring(obj);
|
|
|
|
if (rpool->rp_uri == NULL) {
|
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
|
|
|
rv = errno;
|
|
|
|
goto out;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
2010-04-20 17:52:38 +05:30
|
|
|
rpool->rp_repod = prop_dictionary_internalize_from_zfile(plist);
|
2009-11-30 16:54:04 +05:30
|
|
|
if (rpool->rp_repod == NULL) {
|
2010-01-18 04:56:50 +05:30
|
|
|
free(rpool->rp_uri);
|
|
|
|
free(rpool);
|
2009-11-26 07:52:50 +05:30
|
|
|
free(plist);
|
2009-11-27 02:11:46 +05:30
|
|
|
if (errno == ENOENT) {
|
|
|
|
errno = 0;
|
|
|
|
nmissing++;
|
|
|
|
continue;
|
|
|
|
}
|
2009-11-26 07:52:50 +05:30
|
|
|
rv = errno;
|
2009-11-27 02:11:46 +05:30
|
|
|
goto out;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
|
|
|
free(plist);
|
2010-01-21 07:40:19 +05:30
|
|
|
SIMPLEQ_INSERT_TAIL(&rp_queue, rpool, rp_entries);
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
|
|
|
|
2009-11-27 06:21:30 +05:30
|
|
|
if (ntotal - nmissing == 0)
|
2009-11-27 02:11:46 +05:30
|
|
|
goto out;
|
|
|
|
|
2009-11-26 07:52:50 +05:30
|
|
|
repolist_initialized = true;
|
|
|
|
repolist_refcnt = 1;
|
|
|
|
DPRINTF(("%s: initialized ok.\n", __func__));
|
|
|
|
out:
|
2009-11-27 02:11:46 +05:30
|
|
|
if (iter)
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
if (dict)
|
|
|
|
prop_object_release(dict);
|
2009-11-26 07:52:50 +05:30
|
|
|
if (rv != 0)
|
|
|
|
xbps_repository_pool_release();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
void
|
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
|
|
|
|
|
|
|
if (--repolist_refcnt > 0)
|
|
|
|
return;
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
while ((rpool = SIMPLEQ_FIRST(&rp_queue)) != NULL) {
|
|
|
|
SIMPLEQ_REMOVE(&rp_queue, rpool, repository_pool, rp_entries);
|
2009-11-30 16:54:04 +05:30
|
|
|
prop_object_release(rpool->rp_repod);
|
|
|
|
free(rpool->rp_uri);
|
|
|
|
free(rpool);
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
|
|
|
repolist_refcnt = 0;
|
|
|
|
repolist_initialized = false;
|
|
|
|
DPRINTF(("%s: released ok.\n", __func__));
|
|
|
|
}
|