rpool: switch "struct xbps_repo" to be part of the rpool simpleq.
The previous internal "struct rpool" was an extra structure that can be avoided by just using "struct xbps_repo" directly. This makes rpool use (at least) 4KB less per repository and 1 extra allocation.
This commit is contained in:
parent
b1309644e5
commit
67cfc4ebad
@ -27,6 +27,7 @@
|
|||||||
#ifndef _XBPS_API_H_
|
#ifndef _XBPS_API_H_
|
||||||
#define _XBPS_API_H_
|
#define _XBPS_API_H_
|
||||||
|
|
||||||
|
#include <sys/queue.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
@ -46,7 +47,7 @@
|
|||||||
*
|
*
|
||||||
* This header documents the full API for the XBPS Library.
|
* This header documents the full API for the XBPS Library.
|
||||||
*/
|
*/
|
||||||
#define XBPS_API_VERSION "20131118"
|
#define XBPS_API_VERSION "20131216"
|
||||||
|
|
||||||
#ifndef XBPS_VERSION
|
#ifndef XBPS_VERSION
|
||||||
#define XBPS_VERSION "UNSET"
|
#define XBPS_VERSION "UNSET"
|
||||||
@ -1110,6 +1111,7 @@ struct xbps_repo {
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
SIMPLEQ_ENTRY(xbps_repo) entries;
|
||||||
struct archive *ar;
|
struct archive *ar;
|
||||||
/**
|
/**
|
||||||
* @var xhp
|
* @var xhp
|
||||||
|
58
lib/rpool.c
58
lib/rpool.c
@ -33,12 +33,7 @@
|
|||||||
|
|
||||||
#include "xbps_api_impl.h"
|
#include "xbps_api_impl.h"
|
||||||
|
|
||||||
struct rpool {
|
static SIMPLEQ_HEAD(rpool_head, xbps_repo) rpool_queue =
|
||||||
SIMPLEQ_ENTRY(rpool) entries;
|
|
||||||
struct xbps_repo *repo;
|
|
||||||
};
|
|
||||||
|
|
||||||
static SIMPLEQ_HEAD(rpool_head, rpool) rpool_queue =
|
|
||||||
SIMPLEQ_HEAD_INITIALIZER(rpool_queue);
|
SIMPLEQ_HEAD_INITIALIZER(rpool_queue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +45,7 @@ static SIMPLEQ_HEAD(rpool_head, rpool) rpool_queue =
|
|||||||
int HIDDEN
|
int HIDDEN
|
||||||
xbps_rpool_init(struct xbps_handle *xhp)
|
xbps_rpool_init(struct xbps_handle *xhp)
|
||||||
{
|
{
|
||||||
struct rpool *rp;
|
struct xbps_repo *repo;
|
||||||
const char *repouri;
|
const char *repouri;
|
||||||
bool foundrepo = false;
|
bool foundrepo = false;
|
||||||
int retval, rv = 0;
|
int retval, rv = 0;
|
||||||
@ -61,27 +56,25 @@ xbps_rpool_init(struct xbps_handle *xhp)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) {
|
for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) {
|
||||||
rp = malloc(sizeof(struct rpool));
|
|
||||||
assert(rp);
|
|
||||||
xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri);
|
xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri);
|
||||||
if ((rp->repo = xbps_repo_open(xhp, repouri)) == NULL) {
|
if ((repo = xbps_repo_open(xhp, repouri)) == NULL) {
|
||||||
rp->repo = calloc(1, sizeof(struct xbps_repo));
|
repo = calloc(1, sizeof(struct xbps_repo));
|
||||||
assert(rp->repo);
|
assert(repo);
|
||||||
rp->repo->xhp = xhp;
|
repo->xhp = xhp;
|
||||||
rp->repo->uri = repouri;
|
repo->uri = repouri;
|
||||||
if (xbps_repository_is_remote(repouri))
|
if (xbps_repository_is_remote(repouri))
|
||||||
rp->repo->is_remote = true;
|
repo->is_remote = true;
|
||||||
}
|
}
|
||||||
if (rp->repo->is_remote) {
|
if (repo->is_remote) {
|
||||||
if (!rp->repo->is_signed) {
|
if (!repo->is_signed) {
|
||||||
/* ignore unsigned repositories */
|
/* ignore unsigned repositories */
|
||||||
xbps_repo_invalidate(rp->repo);
|
xbps_repo_invalidate(repo);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Check the repository index signature against
|
* Check the repository index signature against
|
||||||
* stored public key.
|
* stored public key.
|
||||||
*/
|
*/
|
||||||
retval = xbps_repo_key_verify(rp->repo);
|
retval = xbps_repo_key_verify(repo);
|
||||||
if (retval == 0) {
|
if (retval == 0) {
|
||||||
/* signed, verified */
|
/* signed, verified */
|
||||||
xbps_set_cb_state(xhp, XBPS_STATE_REPO_SIGVERIFIED,
|
xbps_set_cb_state(xhp, XBPS_STATE_REPO_SIGVERIFIED,
|
||||||
@ -90,23 +83,23 @@ xbps_rpool_init(struct xbps_handle *xhp)
|
|||||||
/* signed, unverified */
|
/* signed, unverified */
|
||||||
xbps_set_cb_state(xhp, XBPS_STATE_REPO_SIGUNVERIFIED,
|
xbps_set_cb_state(xhp, XBPS_STATE_REPO_SIGUNVERIFIED,
|
||||||
0, repouri, NULL);
|
0, repouri, NULL);
|
||||||
xbps_repo_invalidate(rp->repo);
|
xbps_repo_invalidate(repo);
|
||||||
} else {
|
} else {
|
||||||
/* any error */
|
/* any error */
|
||||||
xbps_dbg_printf(xhp, "[rpool] %s: key_verify %s\n",
|
xbps_dbg_printf(xhp, "[rpool] %s: key_verify %s\n",
|
||||||
repouri, strerror(retval));
|
repouri, strerror(retval));
|
||||||
xbps_repo_invalidate(rp->repo);
|
xbps_repo_invalidate(repo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* If repository has passed signature checks, add it to the pool.
|
* If repository has passed signature checks, add it to the pool.
|
||||||
*/
|
*/
|
||||||
SIMPLEQ_INSERT_TAIL(&rpool_queue, rp, entries);
|
SIMPLEQ_INSERT_TAIL(&rpool_queue, repo, entries);
|
||||||
foundrepo = true;
|
foundrepo = true;
|
||||||
xbps_dbg_printf(xhp, "[rpool] `%s' registered (%s, %s).\n",
|
xbps_dbg_printf(xhp, "[rpool] `%s' registered (%s, %s).\n",
|
||||||
repouri, rp->repo->is_signed ? "signed" : "unsigned",
|
repouri, repo->is_signed ? "signed" : "unsigned",
|
||||||
rp->repo->is_verified ? "verified" : "unverified");
|
repo->is_verified ? "verified" : "unverified");
|
||||||
}
|
}
|
||||||
if (!foundrepo) {
|
if (!foundrepo) {
|
||||||
/* no repositories available, error out */
|
/* no repositories available, error out */
|
||||||
@ -126,16 +119,15 @@ out:
|
|||||||
void HIDDEN
|
void HIDDEN
|
||||||
xbps_rpool_release(struct xbps_handle *xhp)
|
xbps_rpool_release(struct xbps_handle *xhp)
|
||||||
{
|
{
|
||||||
struct rpool *rp;
|
struct xbps_repo *repo;
|
||||||
|
|
||||||
if (!xhp->rpool_initialized)
|
if (!xhp->rpool_initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while ((rp = SIMPLEQ_FIRST(&rpool_queue))) {
|
while ((repo = SIMPLEQ_FIRST(&rpool_queue))) {
|
||||||
SIMPLEQ_REMOVE(&rpool_queue, rp, rpool, entries);
|
SIMPLEQ_REMOVE(&rpool_queue, repo, xbps_repo, entries);
|
||||||
xbps_repo_close(rp->repo);
|
xbps_repo_close(repo);
|
||||||
free(rp->repo);
|
free(repo);
|
||||||
free(rp);
|
|
||||||
}
|
}
|
||||||
xhp->rpool_initialized = false;
|
xhp->rpool_initialized = false;
|
||||||
xbps_dbg_printf(xhp, "[rpool] released ok.\n");
|
xbps_dbg_printf(xhp, "[rpool] released ok.\n");
|
||||||
@ -168,7 +160,7 @@ xbps_rpool_foreach(struct xbps_handle *xhp,
|
|||||||
int (*fn)(struct xbps_repo *, void *, bool *),
|
int (*fn)(struct xbps_repo *, void *, bool *),
|
||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
struct rpool *rp;
|
struct xbps_repo *repo;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
||||||
@ -183,8 +175,8 @@ xbps_rpool_foreach(struct xbps_handle *xhp,
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
/* Iterate over repository pool */
|
/* Iterate over repository pool */
|
||||||
SIMPLEQ_FOREACH(rp, &rpool_queue, entries) {
|
SIMPLEQ_FOREACH(repo, &rpool_queue, entries) {
|
||||||
rv = (*fn)(rp->repo, arg, &done);
|
rv = (*fn)(repo, arg, &done);
|
||||||
if (rv != 0 || done)
|
if (rv != 0 || done)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user