Use a single file to store repository data.

This is just the starting point to extend repositories with PGP signatures.
This commit is contained in:
Juan RP
2013-06-10 10:28:39 +02:00
parent fa9d3471d9
commit 99be698979
28 changed files with 666 additions and 548 deletions

View File

@@ -1,6 +1,6 @@
-include ../config.mk
LIBXBPS_MAJOR = 1
LIBXBPS_MAJOR = 2
LIBXBPS_MINOR = 0
LIBXBPS_MICRO = 0
LIBXBPS_SHLIB = libxbps.so.$(LIBXBPS_MAJOR).$(LIBXBPS_MINOR).$(LIBXBPS_MICRO)
@@ -46,9 +46,9 @@ OBJS += package_unpack.o package_register.o package_script.o
OBJS += transaction_commit.o transaction_package_replace.o
OBJS += transaction_dictionary.o transaction_sortdeps.o transaction_ops.o
OBJS += download.o initend.o pkgdb.o package_conflicts.o
OBJS += plist.o plist_archive_entry.o plist_find.o plist_match.o
OBJS += plist.o plist_find.o plist_match.o archive.o
OBJS += plist_remove.o plist_fetch.o util.o util_hash.o
OBJS += rindex_pkgdeps.o rindex_sync.o rindex_get.o
OBJS += repo.o repo_pkgdeps.o repo_sync.o
OBJS += rpool.o rpool_get.o cb_util.o
OBJS += $(EXTOBJS) $(COMPAT_SRCS)

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2012 Juan Romero Pardines.
* Copyright (c) 2008-2013 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -39,7 +39,7 @@
#define _READ_CHUNK 8192
static char *
_xbps_uncompress_plist_data(char *xml, size_t len)
uncompress_plist_data(char *xml, size_t len)
{
z_stream strm;
unsigned char *out;
@@ -83,16 +83,16 @@ _xbps_uncompress_plist_data(char *xml, size_t len)
strm.next_out = out;
rv = inflate(&strm, Z_NO_FLUSH);
switch (rv) {
case Z_DATA_ERROR:
case Z_STREAM_ERROR:
case Z_NEED_DICT:
case Z_MEM_ERROR:
case Z_BUF_ERROR:
case Z_VERSION_ERROR:
(void)inflateEnd(&strm);
free(uncomp_xml);
free(out);
return NULL;
case Z_DATA_ERROR:
case Z_STREAM_ERROR:
case Z_NEED_DICT:
case Z_MEM_ERROR:
case Z_BUF_ERROR:
case Z_VERSION_ERROR:
(void)inflateEnd(&strm);
free(uncomp_xml);
free(out);
return NULL;
}
have = _READ_CHUNK - strm.avail_out;
totalsize += have;
@@ -109,8 +109,7 @@ _xbps_uncompress_plist_data(char *xml, size_t len)
#undef _READ_CHUNK
prop_dictionary_t HIDDEN
xbps_dictionary_from_archive_entry(struct archive *ar,
struct archive_entry *entry)
xbps_archive_get_dictionary(struct archive *ar, struct archive_entry *entry)
{
prop_dictionary_t d = NULL;
size_t buflen;
@@ -137,7 +136,7 @@ xbps_dictionary_from_archive_entry(struct archive *ar,
goto out;
/* Try to uncompress blob */
uncomp_buf = _xbps_uncompress_plist_data(buf, buflen);
uncomp_buf = uncompress_plist_data(buf, buflen);
if (uncomp_buf == NULL) {
/* Error while decompressing */
free(buf);
@@ -152,3 +151,42 @@ out:
free(buf);
return d;
}
int
xbps_archive_append_buf(struct archive *ar, const void *buf, const size_t buflen,
const char *fname, const mode_t mode, const char *uname, const char *gname)
{
struct archive_entry *entry;
time_t tm;
assert(ar);
assert(buf);
assert(fname);
assert(uname);
assert(gname);
tm = time(NULL);
entry = archive_entry_new();
assert(entry);
archive_entry_set_filetype(entry, AE_IFREG);
archive_entry_set_perm(entry, mode);
archive_entry_set_uname(entry, uname);
archive_entry_set_gname(entry, gname);
archive_entry_set_pathname(entry, fname);
archive_entry_set_size(entry, buflen);
archive_entry_set_atime(entry, tm, 0);
archive_entry_set_mtime(entry, tm, 0);
archive_entry_set_ctime(entry, tm, 0);
if (archive_write_header(ar, entry) != ARCHIVE_OK)
return archive_errno(ar);
if (archive_write_data(ar, buf, buflen) != ARCHIVE_OK)
return archive_errno(ar);
archive_write_finish_entry(ar);
archive_entry_free(entry);
return 0;
}

View File

@@ -172,7 +172,6 @@ xbps_remove_pkg(struct xbps_handle *xhp,
{
prop_dictionary_t pkgd = NULL;
char *pkgname, *buf = NULL;
const char *version;
int rv = 0;
pkg_state_t state = 0;
@@ -181,8 +180,6 @@ xbps_remove_pkg(struct xbps_handle *xhp,
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
version = xbps_pkg_version(pkgver);
assert(version);
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0)
goto out;

View File

@@ -281,14 +281,14 @@ unpack_archive(struct xbps_handle *xhp,
continue;
} else if (strcmp("./files.plist", entry_pname) == 0) {
filesd = xbps_dictionary_from_archive_entry(ar, entry);
filesd = xbps_archive_get_dictionary(ar, entry);
if (filesd == NULL) {
rv = errno;
goto out;
}
continue;
} else if (strcmp("./props.plist", entry_pname) == 0) {
propsd = xbps_dictionary_from_archive_entry(ar, entry);
propsd = xbps_archive_get_dictionary(ar, entry);
if (propsd == NULL) {
rv = errno;
goto out;

View File

@@ -180,7 +180,7 @@ xbps_get_pkg_plist_from_binpkg(const char *fname, const char *plistf)
i++;
continue;
}
plistd = xbps_dictionary_from_archive_entry(a, entry);
plistd = xbps_archive_get_dictionary(a, entry);
if (plistd == NULL) {
errno = EINVAL;
break;

191
lib/repo.c Normal file
View File

@@ -0,0 +1,191 @@
/*-
* Copyright (c) 2012-2013 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_impl.h"
/**
* @file lib/repo.c
* @brief Repository functions
* @defgroup repo Repository functions
*/
char *
xbps_repo_path(struct xbps_handle *xhp, const char *url)
{
assert(xhp);
assert(url);
return xbps_xasprintf("%s/%s-repodata",
url, xhp->target_arch ? xhp->target_arch : xhp->native_arch);
}
struct xbps_repo *
xbps_repo_open(struct xbps_handle *xhp, const char *url)
{
struct xbps_repo *repo;
const char *arch;
char *repofile;
assert(xhp);
assert(url);
if (xhp->target_arch)
arch = xhp->target_arch;
else
arch = xhp->native_arch;
if (xbps_repository_is_remote(url)) {
/* remote repository */
char *rpath;
if ((rpath = xbps_get_remote_repo_string(url)) == NULL)
return NULL;
repofile = xbps_xasprintf("%s/%s/%s-repodata", xhp->metadir, rpath, arch);
free(rpath);
} else {
/* local repository */
repofile = xbps_repo_path(xhp, url);
}
repo = calloc(1, sizeof(struct xbps_repo));
assert(repo);
repo->xhp = xhp;
repo->uri = url;
repo->ar = archive_read_new();
archive_read_support_filter_gzip(repo->ar);
archive_read_support_format_tar(repo->ar);
if (archive_read_open_filename(repo->ar, repofile, ARCHIVE_READ_BLOCKSIZE)) {
xbps_dbg_printf(xhp, "cannot open repository file %s: %s\n",
repofile, strerror(archive_errno(repo->ar)));
archive_read_free(repo->ar);
free(repo);
repo = NULL;
}
free(repofile);
return repo;
}
prop_dictionary_t
xbps_repo_get_plist(struct xbps_repo *repo, const char *file)
{
prop_dictionary_t d;
struct archive_entry *entry;
void *buf;
size_t buflen;
ssize_t nbytes = -1;
int rv;
assert(repo);
assert(repo->ar);
assert(file);
for (;;) {
rv = archive_read_next_header(repo->ar, &entry);
if (rv == ARCHIVE_EOF || rv == ARCHIVE_FATAL)
break;
else if (rv == ARCHIVE_RETRY)
continue;
if (strcmp(archive_entry_pathname(entry), file) == 0) {
buflen = (size_t)archive_entry_size(entry);
buf = malloc(buflen);
assert(buf);
nbytes = archive_read_data(repo->ar, buf, buflen);
if ((size_t)nbytes != buflen) {
free(buf);
return NULL;
}
d = prop_dictionary_internalize(buf);
free(buf);
return d;
}
archive_read_data_skip(repo->ar);
}
return NULL;
}
void
xbps_repo_close(struct xbps_repo *repo)
{
assert(repo);
archive_read_free(repo->ar);
if (prop_object_type(repo->idx) == PROP_TYPE_DICTIONARY)
prop_object_release(repo->idx);
if (prop_object_type(repo->idxfiles) == PROP_TYPE_DICTIONARY)
prop_object_release(repo->idxfiles);
free(repo);
}
prop_dictionary_t
xbps_repo_get_virtualpkg(struct xbps_repo *repo, const char *pkg)
{
prop_dictionary_t pkgd;
assert(repo);
assert(repo->ar);
assert(pkg);
if (prop_object_type(repo->idx) != PROP_TYPE_DICTIONARY) {
repo->idx = xbps_repo_get_plist(repo, XBPS_PKGINDEX);
assert(repo->idx);
}
pkgd = xbps_find_virtualpkg_in_dict(repo->xhp, repo->idx, pkg);
if (pkgd) {
prop_dictionary_set_cstring_nocopy(pkgd,
"repository", repo->uri);
return pkgd;
}
return NULL;
}
prop_dictionary_t
xbps_repo_get_pkg(struct xbps_repo *repo, const char *pkg)
{
prop_dictionary_t pkgd;
assert(repo);
assert(repo->ar);
assert(pkg);
if (prop_object_type(repo->idx) != PROP_TYPE_DICTIONARY) {
repo->idx = xbps_repo_get_plist(repo, XBPS_PKGINDEX);
assert(repo->idx);
}
pkgd = xbps_find_pkg_in_dict(repo->idx, pkg);
if (pkgd) {
prop_dictionary_set_cstring_nocopy(pkgd,
"repository", repo->uri);
return pkgd;
}
return NULL;
}

View File

@@ -72,10 +72,10 @@ xbps_get_remote_repo_string(const char *uri)
* size and/or mtime match) and 1 if downloaded successfully.
*/
int HIDDEN
xbps_rindex_sync(struct xbps_handle *xhp, const char *uri, const char *plistf)
xbps_repo_sync(struct xbps_handle *xhp, const char *uri)
{
const char *arch, *fetchstr = NULL;
char *rpidx, *lrepodir, *uri_fixedp;
char *repodata, *lrepodir, *uri_fixedp;
int rv = 0;
assert(uri != NULL);
@@ -124,24 +124,24 @@ xbps_rindex_sync(struct xbps_handle *xhp, const char *uri, const char *plistf)
/*
* Remote repository plist index full URL.
*/
rpidx = xbps_xasprintf("%s/%s-%s", uri, arch, plistf);
repodata = xbps_xasprintf("%s/%s-repodata", uri, arch);
/* reposync start cb */
xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC, 0, rpidx, NULL);
xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC, 0, repodata, NULL);
/*
* Download plist index file from repository.
*/
if ((rv = xbps_fetch_file(xhp, rpidx, NULL)) == -1) {
if ((rv = xbps_fetch_file(xhp, repodata, NULL)) == -1) {
/* reposync error cb */
fetchstr = xbps_fetch_error_string();
xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC_FAIL,
fetchLastErrCode != 0 ? fetchLastErrCode : errno, NULL,
"[reposync] failed to fetch file `%s': %s",
rpidx, fetchstr ? fetchstr : strerror(errno));
repodata, fetchstr ? fetchstr : strerror(errno));
} else if (rv == 1)
rv = 0;
free(rpidx);
free(repodata);
return rv;
}

View File

@@ -1,66 +0,0 @@
/*-
* Copyright (c) 2012-2013 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_impl.h"
/**
* @file lib/rindex_get.c
* @brief Repository index functions
* @defgroup rindex Repository index functions
*/
prop_dictionary_t
xbps_rindex_get_virtualpkg(struct xbps_rindex *rpi, const char *pkg)
{
prop_dictionary_t pkgd;
pkgd = xbps_find_virtualpkg_in_dict(rpi->xhp, rpi->repod, pkg);
if (pkgd) {
prop_dictionary_set_cstring_nocopy(pkgd,
"repository", rpi->uri);
return pkgd;
}
return NULL;
}
prop_dictionary_t
xbps_rindex_get_pkg(struct xbps_rindex *rpi, const char *pkg)
{
prop_dictionary_t pkgd;
pkgd = xbps_find_pkg_in_dict(rpi->repod, pkg);
if (pkgd) {
prop_dictionary_set_cstring_nocopy(pkgd,
"repository", rpi->uri);
return pkgd;
}
return NULL;
}

View File

@@ -33,6 +33,14 @@
#include "xbps_api_impl.h"
struct rpool {
SIMPLEQ_ENTRY(rpool) entries;
struct xbps_repo *repo;
};
static SIMPLEQ_HEAD(rpool_head, rpool) rpool_queue =
SIMPLEQ_HEAD_INITIALIZER(rpool_queue);
/**
* @file lib/rpool.c
* @brief Repository pool routines
@@ -42,81 +50,45 @@
int HIDDEN
xbps_rpool_init(struct xbps_handle *xhp)
{
prop_dictionary_t repod, d = NULL;
size_t i, ntotal = 0, nmissing = 0;
struct rpool *rp;
const char *repouri;
char *plist;
unsigned int i;
bool foundrepo = false;
int rv = 0;
if (xhp->repo_pool != NULL)
assert(xhp);
if (xhp->rpool_initialized)
return 0;
else if (xhp->cfg == NULL)
return ENOTSUP;
xhp->repo_pool = prop_array_create();
if (xhp->repo_pool == NULL)
return ENOMEM;
for (i = 0; i < cfg_size(xhp->cfg, "repositories"); i++) {
rp = malloc(sizeof(struct rpool));
assert(rp);
repouri = cfg_getnstr(xhp->cfg, "repositories", i);
ntotal++;
/*
* If index file is not there, skip.
*/
plist = xbps_pkg_index_plist(xhp, repouri);
if (plist == NULL) {
rv = errno;
goto out;
}
if (access(plist, R_OK) == -1) {
xbps_dbg_printf(xhp, "[rpool] `%s' cannot be "
"internalized: %s\n", repouri, strerror(errno));
nmissing++;
if ((rp->repo = xbps_repo_open(xhp, repouri)) == NULL) {
free(rp);
continue;
}
repod = prop_dictionary_internalize_from_zfile(plist);
free(plist);
if (prop_object_type(repod) != PROP_TYPE_DICTIONARY) {
xbps_dbg_printf(xhp, "[rpool] `%s' cannot be "
"internalized: %s\n", repouri, strerror(errno));
nmissing++;
rp->repo->idx = xbps_repo_get_plist(rp->repo, XBPS_PKGINDEX);
if (rp->repo->idx == NULL) {
xbps_repo_close(rp->repo);
free(rp);
continue;
}
/*
* Register repository into the array.
*/
if ((d = prop_dictionary_create()) == NULL) {
rv = ENOMEM;
prop_object_release(repod);
goto out;
}
if (!prop_dictionary_set_cstring_nocopy(d, "uri", repouri)) {
rv = EINVAL;
prop_object_release(repod);
prop_object_release(d);
goto out;
}
if (!prop_dictionary_set(d, "index", repod)) {
rv = EINVAL;
prop_object_release(repod);
prop_object_release(d);
goto out;
}
prop_object_release(repod);
if (!prop_array_add(xhp->repo_pool, d)) {
rv = EINVAL;
prop_object_release(d);
goto out;
}
rp->repo->uri = repouri;
rp->repo->xhp = xhp;
SIMPLEQ_INSERT_TAIL(&rpool_queue, rp, entries);
foundrepo = true;
xbps_dbg_printf(xhp, "[rpool] `%s' registered.\n", repouri);
}
if (ntotal - nmissing == 0) {
if (!foundrepo) {
/* no repositories available, error out */
rv = ENOTSUP;
goto out;
}
prop_array_make_immutable(xhp->repo_pool);
xhp->rpool_initialized = true;
xbps_dbg_printf(xhp, "[rpool] initialized ok.\n");
out:
if (rv != 0)
@@ -129,29 +101,22 @@ out:
void HIDDEN
xbps_rpool_release(struct xbps_handle *xhp)
{
prop_dictionary_t d;
size_t i;
const char *uri;
struct rpool *rp;
if (xhp->repo_pool == NULL)
if (!xhp->rpool_initialized)
return;
for (i = 0; i < prop_array_count(xhp->repo_pool); i++) {
d = prop_array_get(xhp->repo_pool, i);
if (xhp->flags & XBPS_FLAG_DEBUG) {
prop_dictionary_get_cstring_nocopy(d, "uri", &uri);
xbps_dbg_printf(xhp, "[rpool] unregistered "
"repository '%s'\n", uri);
}
prop_object_release(d);
while ((rp = SIMPLEQ_FIRST(&rpool_queue))) {
SIMPLEQ_REMOVE(&rpool_queue, rp, rpool, entries);
xbps_repo_close(rp->repo);
free(rp);
}
prop_object_release(xhp->repo_pool);
xhp->repo_pool = NULL;
xhp->rpool_initialized = false;
xbps_dbg_printf(xhp, "[rpool] released ok.\n");
}
int
xbps_rpool_sync(struct xbps_handle *xhp, const char *file, const char *uri)
xbps_rpool_sync(struct xbps_handle *xhp, const char *uri)
{
const char *repouri;
size_t i;
@@ -165,11 +130,10 @@ xbps_rpool_sync(struct xbps_handle *xhp, const char *file, const char *uri)
if (uri && strcmp(repouri, uri))
continue;
if (xbps_rindex_sync(xhp, repouri, file) == -1) {
if (xbps_repo_sync(xhp, repouri) == -1) {
xbps_dbg_printf(xhp,
"[rpool] `%s' failed to fetch `%s': %s\n",
repouri, file,
fetchLastErrCode == 0 ? strerror(errno) :
"[rpool] `%s' failed to fetch repository data: %s\n",
repouri, fetchLastErrCode == 0 ? strerror(errno) :
xbps_fetch_error_string());
continue;
}
@@ -179,12 +143,10 @@ xbps_rpool_sync(struct xbps_handle *xhp, const char *file, const char *uri)
int
xbps_rpool_foreach(struct xbps_handle *xhp,
int (*fn)(struct xbps_rindex *, void *, bool *),
int (*fn)(struct xbps_repo *, void *, bool *),
void *arg)
{
prop_dictionary_t d;
struct xbps_rindex rpi;
size_t i;
struct rpool *rp;
int rv = 0;
bool done = false;
@@ -202,12 +164,8 @@ xbps_rpool_foreach(struct xbps_handle *xhp,
return rv;
}
/* Iterate over repository pool */
for (i = 0; i < prop_array_count(xhp->repo_pool); i++) {
d = prop_array_get(xhp->repo_pool, i);
prop_dictionary_get_cstring_nocopy(d, "uri", &rpi.uri);
rpi.repod = prop_dictionary_get(d, "index");
rpi.xhp = xhp;
rv = (*fn)(&rpi, arg, &done);
SIMPLEQ_FOREACH(rp, &rpool_queue, entries) {
rv = (*fn)(rp->repo, arg, &done);
if (rv != 0 || done)
break;
}

View File

@@ -44,11 +44,11 @@ struct rpool_fpkg {
};
static int
find_virtualpkg_cb(struct xbps_rindex *rpi, void *arg, bool *done)
find_virtualpkg_cb(struct xbps_repo *repo, void *arg, bool *done)
{
struct rpool_fpkg *rpf = arg;
rpf->pkgd = xbps_rindex_get_virtualpkg(rpi, rpf->pattern);
rpf->pkgd = xbps_repo_get_virtualpkg(repo, rpf->pattern);
if (rpf->pkgd) {
/* found */
*done = true;
@@ -59,11 +59,11 @@ find_virtualpkg_cb(struct xbps_rindex *rpi, void *arg, bool *done)
}
static int
find_pkg_cb(struct xbps_rindex *rpi, void *arg, bool *done)
find_pkg_cb(struct xbps_repo *repo, void *arg, bool *done)
{
struct rpool_fpkg *rpf = arg;
rpf->pkgd = xbps_rindex_get_pkg(rpi, rpf->pattern);
rpf->pkgd = xbps_repo_get_pkg(repo, rpf->pattern);
if (rpf->pkgd) {
/* found */
*done = true;
@@ -74,7 +74,7 @@ find_pkg_cb(struct xbps_rindex *rpi, void *arg, bool *done)
}
static int
find_best_pkg_cb(struct xbps_rindex *rpi, void *arg, bool *done)
find_best_pkg_cb(struct xbps_repo *repo, void *arg, bool *done)
{
struct rpool_fpkg *rpf = arg;
prop_dictionary_t pkgd;
@@ -82,25 +82,25 @@ find_best_pkg_cb(struct xbps_rindex *rpi, void *arg, bool *done)
(void)done;
pkgd = xbps_rindex_get_pkg(rpi, rpf->pattern);
pkgd = xbps_repo_get_pkg(repo, rpf->pattern);
if (pkgd == NULL) {
if (errno && errno != ENOENT)
return errno;
xbps_dbg_printf(rpi->xhp,
xbps_dbg_printf(repo->xhp,
"[rpool] Package '%s' not found in repository "
"'%s'.\n", rpf->pattern, rpi->uri);
"'%s'.\n", rpf->pattern, repo->uri);
return 0;
}
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &repopkgver);
if (rpf->bestpkgver == NULL) {
xbps_dbg_printf(rpi->xhp,
xbps_dbg_printf(repo->xhp,
"[rpool] Found best match '%s' (%s).\n",
repopkgver, rpi->uri);
repopkgver, repo->uri);
rpf->pkgd = pkgd;
prop_dictionary_set_cstring_nocopy(rpf->pkgd,
"repository", rpi->uri);
"repository", repo->uri);
rpf->bestpkgver = repopkgver;
return 0;
}
@@ -109,12 +109,12 @@ find_best_pkg_cb(struct xbps_rindex *rpi, void *arg, bool *done)
* version from current package in repository.
*/
if (xbps_cmpver(repopkgver, rpf->bestpkgver) == 1) {
xbps_dbg_printf(rpi->xhp,
xbps_dbg_printf(repo->xhp,
"[rpool] Found best match '%s' (%s).\n",
repopkgver, rpi->uri);
repopkgver, repo->uri);
rpf->pkgd = pkgd;
prop_dictionary_set_cstring_nocopy(rpf->pkgd,
"repository", rpi->uri);
"repository", repo->uri);
rpf->bestpkgver = repopkgver;
}
return 0;

View File

@@ -29,7 +29,6 @@
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <assert.h>
#include <unistd.h>
#include <limits.h>

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2012 Juan Romero Pardines.
* Copyright (c) 2008-2013 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,6 +27,10 @@
# define _GNU_SOURCE /* for vasprintf(3) */
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -36,9 +40,6 @@
#include <fnmatch.h>
#include <sys/utsname.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "xbps_api_impl.h"
#ifdef __clang__
@@ -170,69 +171,6 @@ xbps_pkgpattern_version(const char *pkg)
return strpbrk(pkg, "><*?[]");
}
static char *
get_pkg_index_remote_plist(struct xbps_handle *xhp,
const char *uri,
const char *plistf)
{
const char *arch;
char *uri_fixed, *repodir;
assert(uri != NULL);
uri_fixed = xbps_get_remote_repo_string(uri);
if (uri_fixed == NULL)
return NULL;
if (xhp->target_arch)
arch = xhp->target_arch;
else
arch = xhp->native_arch;
repodir = xbps_xasprintf("%s/%s/%s-%s", xhp->metadir,
uri_fixed, arch, plistf);
free(uri_fixed);
return repodir;
}
char *
xbps_pkg_index_plist(struct xbps_handle *xhp, const char *uri)
{
const char *arch;
assert(xhp);
assert(uri != NULL);
if (xbps_repository_is_remote(uri))
return get_pkg_index_remote_plist(xhp, uri, XBPS_PKGINDEX);
if (xhp->target_arch)
arch = xhp->target_arch;
else
arch = xhp->native_arch;
return xbps_xasprintf("%s/%s-%s", uri, arch, XBPS_PKGINDEX);
}
char *
xbps_pkg_index_files_plist(struct xbps_handle *xhp, const char *uri)
{
const char *arch;
assert(xhp);
assert(uri != NULL);
if (xbps_repository_is_remote(uri))
return get_pkg_index_remote_plist(xhp, uri, XBPS_PKGINDEX_FILES);
if (xhp->target_arch)
arch = xhp->target_arch;
else
arch = xhp->native_arch;
return xbps_xasprintf("%s/%s-%s", uri, arch, XBPS_PKGINDEX_FILES);
}
char HIDDEN *
xbps_repository_pkg_path(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
{