Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add basic support of flexible repo types.
Vsevolod Stakhov committed 11 years ago
commit 234c246d19d8ab03edf8377219fbbe2fb0937ccb
parent 9d1503f
7 files changed +86 -14
modified configure.ac
@@ -290,7 +290,7 @@ AC_CONFIG_COMMANDS([pkg_repos.h], [[
	for rt in $REPOS ; do
		echo "&pkg_repo_${rt}_ops," >> $NMODULES
	done
-
	echo "{NULL}" >> $NMODULES
+
	echo "NULL" >> $NMODULES
	echo "};" >> $NMODULES
	echo "#endif /* PKG_REPOS_H */" >> $NMODULES
	if [ -f pkg_repos.h ] ; then
modified libpkg/pkg.h.in
@@ -309,10 +309,6 @@ typedef enum {
} pkg_list;

typedef enum {
-
	REPO_BINARY_PKGS,
-
} repo_t;
-

-
typedef enum {
	SRV,
	HTTP,
	NOMIRROR,
modified libpkg/pkg_config.c
@@ -45,6 +45,7 @@
#include <ucl.h>

#include "pkg.h"
+
#include "pkg_repos.h"
#include "private/pkg.h"
#include "private/event.h"

@@ -311,7 +312,8 @@ static struct config_entry c[] = {
static bool parsed = false;
static size_t c_size = NELEM(c);

-
static struct pkg_repo	*pkg_repo_new(const char *name, const char *url);
+
static struct pkg_repo* pkg_repo_new(const char *name,
+
	const char *url, const char *type);

static void
connect_evpipe(const char *evpipe) {
@@ -404,6 +406,7 @@ add_repo(const ucl_object_t *obj, struct pkg_repo *r, const char *rname)
	const char *url = NULL, *pubkey = NULL, *mirror_type = NULL;
	const char *signature_type = NULL, *fingerprints = NULL;
	const char *key;
+
	const char *type = NULL;

	pkg_debug(1, "PkgConfig: parsing repository object %s", rname);
	while ((cur = ucl_iterate_object(obj, &it, true))) {
@@ -469,6 +472,14 @@ add_repo(const ucl_object_t *obj, struct pkg_repo *r, const char *rname)
				return;
			}
			fingerprints = ucl_object_tostring(cur);
+
		} else if (strcasecmp(key, "type") == 0) {
+
			if (cur->type != UCL_STRING) {
+
				pkg_emit_error("Expecting a string for the "
+
					"'%s' key of the '%s' repo",
+
					key, rname);
+
				return;
+
			}
+
			type = ucl_object_tostring(cur);
		}
	}

@@ -478,7 +489,7 @@ add_repo(const ucl_object_t *obj, struct pkg_repo *r, const char *rname)
	}

	if (r == NULL)
-
		r = pkg_repo_new(rname, url);
+
		r = pkg_repo_new(rname, url, type);

	if (signature_type != NULL) {
		if (strcasecmp(signature_type, "pubkey") == 0)
@@ -917,14 +928,36 @@ pkg_init(const char *path, const char *reposdir)
	return (EPKG_OK);
}

+
static struct pkg_repo_ops*
+
pkg_repo_find_type(const char *type)
+
{
+
	struct pkg_repo_ops *found = NULL, **cur;
+

+
	/* Default repo type */
+
	if (type == NULL)
+
		return (pkg_repo_find_type("binary"));
+

+
	cur = &repos_ops[0];
+
	while (*cur != NULL) {
+
		if (strcasecmp(type, (*cur)->type) == 0) {
+
			found = *cur;
+
		}
+
		cur ++;
+
	}
+

+
	if (found == NULL)
+
		return (pkg_repo_find_type("binary"));
+

+
	return (found);
+
}
+

static struct pkg_repo *
-
pkg_repo_new(const char *name, const char *url)
+
pkg_repo_new(const char *name, const char *url, const char *type)
{
	struct pkg_repo *r;

	r = calloc(1, sizeof(struct pkg_repo));
-
	r->type = REPO_BINARY_PKGS;
-
	r->update = pkg_repo_update_binary_pkgs;
+
	r->ops = pkg_repo_find_type(type);
	r->url = strdup(url);
	r->signature_type = SIG_NONE;
	r->mirror_type = NOMIRROR;
modified libpkg/pkg_repo_update.c
@@ -601,5 +601,5 @@ cleanup:
int
pkg_update(struct pkg_repo *repo, bool force)
{
-
	return (repo->update(repo, force));
+
	return (repo->ops->update(repo, force));
}
modified libpkg/private/pkg.h
@@ -320,8 +320,28 @@ struct pkg_repo_meta {
	time_t eol;
};

+
struct pkg_repo_ops {
+
	const char *type;
+
	/* Accessing repo */
+
	int (*init)(struct pkg_repo *);
+
	int (*access)(struct pkg_repo *, unsigned);
+
	int (*open)(struct pkg_repo *);
+
	int (*close)(struct pkg_repo *, bool);
+

+
	/* Updating repo */
+
	int (*update)(struct pkg_repo *, bool);
+

+
	/* Query repo */
+
	struct pkgdb_it * (*query)(struct pkg_repo *,
+
					const char *, match_t);
+

+
	/* Fetch package from repo */
+
	int (*fetch_pkg)(struct pkg_repo *, struct pkg *);
+
};
+

struct pkg_repo {
-
	repo_t type;
+
	struct pkg_repo_ops *ops;
+

	char *name;
	char *url;
	char *pubkey;
@@ -345,10 +365,11 @@ struct pkg_repo {

	struct pkg_repo_meta *meta;

-
	int (*update)(struct pkg_repo *, bool);
-

	bool enable;
	UT_hash_handle hh;
+

+
	/* Opaque repository data */
+
	void *repo_data;
};

/* sql helpers */
modified libpkg/repo/binary/Makefile.am
@@ -1,3 +1,12 @@
+
pkg_common_cflags=	-I$(top_srcdir)/libpkg \
+
			@LIBSBUF_INCLUDE@ \
+
			@LDNS_CFLAGS@ \
+
			-I$(top_srcdir)/external/expat/lib \
+
			-I$(top_srcdir)/external/libucl/include \
+
			-I$(top_srcdir)/external/uthash \
+
			-I$(top_srcdir)/external/sqlite \
+
			-Wno-pointer-sign
+

librepo_binary_la_SOURCES= dummy.c
librepo_binary_la_CFLAGS=	$(pkg_common_cflags) -shared

modified libpkg/repo/binary/dummy.c
@@ -21,3 +21,16 @@
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

+
#include "pkg.h"
+
#include "private/pkg.h"
+

+
struct pkg_repo_ops pkg_repo_binary_ops = {
+
	.type = "binary",
+
	.init = NULL,
+
	.access = NULL,
+
	.open = NULL,
+
	.close = NULL,
+
	.update = NULL,
+
	.query = NULL,
+
	.fetch_pkg = NULL
+
};