Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Nuke struct repos*
Baptiste Daroussin committed 14 years ago
commit f80a95b215398bbfca4c3711e9ced0517d4ef99c
parent 90d63ed
6 files changed +36 -304
modified libpkg/pkg.c
@@ -38,6 +38,9 @@ static struct _fields {
	[PKG_REPOURL] = {PKG_REMOTE, 1},
};

+
static int pkg_add_repo_url(struct pkg *pkg, const char *reponame);
+

+

int
pkg_new(struct pkg **pkg, pkg_t type)
{
@@ -1070,29 +1073,17 @@ pkg_copy_tree(struct pkg *pkg, const char *src, const char *dest)
	return (packing_finish(pack));
}

-
int
+
static int
pkg_add_repo_url(struct pkg *pkg, const char *reponame)
{
-
	properties p = NULL;
-
	int fd = -1;
-

-
	assert(pkg != NULL && reponame != NULL);
+
	struct pkg_config_kv *repokv = NULL;

-
	/* 
-
	 * We have the repo name, now we need to find it's URL
-
	 * Using properties(3) here, as we know the 'key' already
-
	 */
-
	if ((fd = open("/etc/pkg/repositories", O_RDONLY)) < 0) {
-
		pkg_emit_errno("open", "/etc/pkg/repositories");
-
		return (EPKG_FATAL);
+
	while (pkg_config_list(PKG_CONFIG_REPOS, &repokv) == EPKG_OK) {
+
		if (strcmp(reponame, pkg_config_kv_get(repokv, PKG_CONFIG_KV_KEY)) == 0) {
+
			pkg_set(pkg, PKG_REPOURL, pkg_config_kv_get(repokv, PKG_CONFIG_KV_VALUE));
+
			return (EPKG_OK);
+
		}
	}

-
	p = properties_read(fd);
-

-
	pkg_set(pkg, PKG_REPOURL, property_find(p, reponame));
-

-
	properties_free(p);
-
	close(fd);
-

-
	return (EPKG_OK);
+
	return (EPKG_FATAL);
}
modified libpkg/pkg.h
@@ -761,89 +761,6 @@ int pkg_fetch_file(const char *url, const char *dest);
int ports_parse_plist(struct pkg *, char *);

/**
-
 * Creates a new repository object
-
 * This function is used for creating a repository
-
 * object that can later be used by pkg_repos_load()
-
 * for loading the repositories from file and pkg_repos_next()
-
 * for iterating over the repositories tail.
-
 * @return EPKG_OK on success and EPKG_FATAL on error
-
 */
-
int pkg_repos_new(struct pkg_repos **repos);
-

-
/**
-
 * Loads the remote repositories from file
-
 * @param repos A valid repository object as received from pkg_repos_new()
-
 * @return EPKG_OK on success and EPKG_FATAL on error
-
 */
-
int pkg_repos_load(struct pkg_repos *repos);
-

-
/**
-
 * Adds a repository entry found from the repositories file to the tail
-
 * @param repos A valid repository object as returned by pkg_repos_new()
-
 * @param re A valid repository entry object
-
 * @return nothing
-
 */
-
void pkg_repos_add(struct pkg_repos *repos, struct pkg_repos_entry *re);
-

-
/**
-
 * Get the next repository from the configuration file
-
 * @param repos A valid repository object as returned by pkg_repos_new()
-
 * @param re A pointer to a repository entry to save the result. Must be set to
-
 * NULL for the first repository entry
-
 * @return EPKG_OK on success and EPKG_END if end of tail is reached
-
 */
-
int pkg_repos_next(struct pkg_repos *repos, struct pkg_repos_entry **re);
-

-
/**
-
 * Frees the memory used by the repository objects
-
 * @param repos A valid repository object as returned by pkg_repos_new()
-
 */
-
void pkg_repos_free(struct pkg_repos *repos);
-

-
/**
-
 * Check if an attached repository exists
-
 * @param repos A valid repository object as returned by pkg_repos_new()
-
 * @param reponame The name of the repository to be checked
-
 * @return EPKG_OK if repository exists and EPKG_FATAL otherwise
-
 */
-
int pkg_repos_exists(struct pkg_repos *repos, const char *reponame);
-

-
/**
-
 * Returns the name associated with a repository entry
-
 * @param re A valid repository entry object
-
 */
-
const char * pkg_repos_get_name(struct pkg_repos_entry *re);
-

-
/**
-
 * Returns the URL associated wth a repository entry
-
 * @param re A valid repository entry object
-
 */
-
const char * pkg_repos_get_url(struct pkg_repos_entry *re);
-

-
/**
-
 * Returns the line from the configuration file where a repository is defined
-
 * @param re A valid repository entry object
-
 */
-
unsigned int pkg_repos_get_line(struct pkg_repos_entry *re);
-

-
/**
-
 * Returns the next database, which is ATTACH'ed to the main one
-
 * @param it A valid pkgdb_it object as received from
-
 * pkgdb_repos_new() call
-
 * @return A string containing the next database attached
-
 * to the main one, or NULL if end of list is reached.
-
 */
-
const char * pkgdb_repos_next(struct pkgdb_it *it);
-

-
/**
-
 * Adds the URL associated with a repository to a package object
-
 * @param pkg A valid package object
-
 * @param reponame The name of the repository (attached database)
-
 * @return EPKG_OK on success and EPKG_FATAL on error
-
 */
-
int pkg_add_repo_url(struct pkg *pkg, const char *reponame);
-

-
/**
 * @todo Document
 */
int pkg_copy_tree(struct pkg *, const char *src, const char *dest);
modified libpkg/pkg_private.h
@@ -112,16 +112,6 @@ struct pkg_jobs_node {
	LIST_ENTRY(pkg_jobs_node) entries;
};

-
struct pkg_repos {
-
	struct pkg_repos_entry {
-
		const char *name;
-
		const char *url;
-
		STAILQ_ENTRY(pkg_repos_entry) entries;
-
	} re;
-

-
	STAILQ_HEAD(repos, pkg_repos_entry) nodes;
-
};
-

struct pkg_user {
	char name[MAXLOGNAME+1];
	char uidstr[8192]; /* taken from pw_util.c */
modified libpkg/pkg_repo.c
@@ -21,44 +21,6 @@
#include "pkg_event.h"
#include "pkg_private.h"

-
static bool
-
pkg_repos_is_reserved_name(struct pkg_repos *repos, const char *repo_name)
-
{
-
	struct pkg_repos_entry *next = NULL;
-

-
	assert(repos != NULL && repo_name != NULL);
-

-
	/* 
-
	 * Find if a repository name already exists.
-
	 *
-
	 * NOTE1: The 'repo' name is always reserved, 
-
	 * as it is being used by default when 
-
	 * working on a single remote repository,
-
	 * which means that PACKAGESITE is defined.
-
	 *
-
	 * NOTE2: The 'main' and 'temp' names are always
-
	 * reserved, because they are the names of the 
-
	 * main and temp databases, 
-
	 * when working with ATTACH'ed databases in
-
	 * multi-repos mode.
-
	 *
-
	 * NOTE3: The 'local' name is always reserved,
-
	 * because this is the name of the local database.
-
	 */
-

-
	if ((strcmp(repo_name, "repo") == 0) ||
-
	    (strcmp(repo_name, "main") == 0) ||
-
	    (strcmp(repo_name, "temp") == 0) ||
-
	    (strcmp(repo_name, "local") == 0))
-
		return (true);
-

-
	while (pkg_repos_next(repos, &next) == EPKG_OK)
-
		if ((strcmp(repo_name, pkg_repos_get_name(next)) == 0))
-
			return (true);
-

-
        return (false);
-
}
-

int
pkg_repo_fetch(struct pkg *pkg)
{
@@ -148,105 +110,6 @@ pkg_repo_fetch(struct pkg *pkg)
	return (retcode);
}

-
int
-
pkg_repos_new(struct pkg_repos **repos)
-
{
-
	if ((*repos = calloc(1, sizeof(struct pkg_repos))) == NULL) {
-
		pkg_emit_errno("calloc", "pkg_repos");
-
		return (EPKG_FATAL);
-
	}
-

-
	STAILQ_INIT(&(*repos)->nodes);
-

-
	return (EPKG_OK);
-
}
-

-
int
-
pkg_repos_load(struct pkg_repos *repos)
-
{
-
	struct pkg_config_kv *repokv;
-
	struct pkg_repos_entry *re;
-
	const char *repo_name;
-

-
        assert(repos != NULL);
-

-
	while (pkg_config_list(PKG_CONFIG_REPOS, &repokv) == EPKG_OK) {
-
		repo_name = pkg_config_kv_get(repokv, PKG_CONFIG_KV_KEY);
-
		if (pkg_repos_is_reserved_name(repos, repo_name)) {
-
			pkg_emit_error("Repository name '%s' is already reserved, ignoring",
-
                                repo_name);
-
			continue;
-
		}
-

-
		if ((re = calloc(1, sizeof(struct pkg_repos_entry))) == NULL) {
-
			pkg_emit_errno("calloc", "pkg_repos_entry");
-
			 return (EPKG_FATAL);
-
		 }
-

-
		re->name = repo_name;
-
		re->url = pkg_config_kv_get(repokv, PKG_CONFIG_KV_VALUE);
-

-
		pkg_repos_add(repos, re);
-
	}
-

-
	return (EPKG_OK);
-
}
-

-
void
-
pkg_repos_add(struct pkg_repos *repos, struct pkg_repos_entry *re)
-
{
-
		STAILQ_INSERT_TAIL(&repos->nodes, re, entries);
-
}
-

-
int
-
pkg_repos_next(struct pkg_repos *repos, struct pkg_repos_entry **re)
-
{
-
	assert(repos != NULL);
-

-
	if (*re == NULL)
-
		*re = STAILQ_FIRST(&repos->nodes);
-
	else
-
		*re = STAILQ_NEXT(*re, entries);
-

-
	if (*re == NULL)
-
		return (EPKG_END);
-

-
	return (EPKG_OK);
-
}
-

-
const char *
-
pkg_repos_get_name(struct pkg_repos_entry *re)
-
{
-
        assert(re != NULL);
-

-
        return (re->name);
-
}
-

-
const char *
-
pkg_repos_get_url(struct pkg_repos_entry *re)
-
{
-
        assert(re != NULL);
-

-
        return (re->url);
-
}
-

-
void
-
pkg_repos_free(struct pkg_repos *repos)
-
{
-
	struct pkg_repos_entry *re;
-

-
	if (repos == NULL)
-
		return;
-

-
	while (!STAILQ_EMPTY(&repos->nodes)) {
-
		re = STAILQ_FIRST(&repos->nodes);
-
		STAILQ_REMOVE_HEAD(&repos->nodes, entries);
-
		free(re);
-
	}
-

-
	free(repos);
-
}
-

static RSA *
load_rsa_private_key(char *rsa_key_path, pem_password_cb *password_cb)
{
modified libpkg/pkgdb.c
@@ -430,8 +430,6 @@ int
pkgdb_open(struct pkgdb **db_p, pkgdb_t type)
{
	struct pkgdb *db = NULL;
-
	struct pkg_repos *repos = NULL;
-
	struct pkg_repos_entry *re = NULL;
	char localpath[MAXPATHLEN + 1];
	char remotepath[MAXPATHLEN + 1];
	const char *dbdir = NULL;
@@ -439,6 +437,7 @@ pkgdb_open(struct pkgdb **db_p, pkgdb_t type)
	bool multirepos_enabled = false;
	struct sbuf *sql = sbuf_new_auto();
	bool create = false;
+
	struct pkg_config_kv *repokv;

	/*
	 * Set the pointer to NULL now. Change it to the real pointer just
@@ -522,59 +521,40 @@ pkgdb_open(struct pkgdb **db_p, pkgdb_t type)
			fprintf(stderr, "\t/!\\  THIS FEATURE IS STILL CONSIDERED EXPERIMENTAL	/!\\\n");
			fprintf(stderr, "\t/!\\		     YOU HAVE BEEN WARNED		/!\\\n\n");

-
			if (pkg_repos_new(&repos) != EPKG_OK) {
-
				pkg_emit_error("cannot create multi repo object");
-
				pkgdb_close(db);
-
				return (EPKG_FATAL);
-
			}

-
			if (pkg_repos_load(repos) != EPKG_OK) {
-
				pkg_emit_error("cannot load repositories");
-
				pkgdb_close(db);
-
				pkg_repos_free(repos);
-
				return (EPKG_FATAL);
-
			}
+
			while (pkg_config_list(PKG_CONFIG_REPOS, &repokv) == EPKG_OK) {
+
				repo_name = pkg_config_kv_get(repokv, PKG_CONFIG_KV_KEY);
+
				/* is is a reserved name ?*/
+
				if ((strcmp(repo_name, "repo") == 0) ||
+
				    (strcmp(repo_name, "main") == 0) ||
+
				    (strcmp(repo_name, "temp") == 0) ||
+
				    (strcmp(repo_name, "local") == 0))
+
					continue;

-
			while (pkg_repos_next(repos, &re) == EPKG_OK) {
-
				repo_name = pkg_repos_get_name(re);
+
				/* is it already attached ?*/
+
				if (is_attached(db->sqlite, repo_name)) {
+
					pkg_emit_error("%s is already listed, ignoring");
+
					continue;
+
				}

				snprintf(remotepath, sizeof(remotepath), "%s/%s.sqlite",
						dbdir, repo_name);

				if (access(remotepath, R_OK) != 0) {
					pkg_emit_errno("access", remotepath);
-
					sbuf_finish(sql);
					sbuf_delete(sql);
					pkgdb_close(db);
-
					pkg_repos_free(repos);
					return (EPKG_FATAL);
				}

				sbuf_printf(sql, "ATTACH '%s' AS '%s';", remotepath, repo_name);
+
				if (sql_exec(db->sqlite, sbuf_get(sql)) != EPKG_OK) {
+
					sbuf_delete(sql);
+
					pkgdb_close(db);
+
					return (EPKG_FATAL);
+
				}
			}

-
			sbuf_finish(sql);
-

-
			/* 
-
			 * Check if a default repo is defined.
-
			 */
-
			if (pkg_repos_exists(repos, "default")) {
-
				pkg_emit_error("no default repository defined");
-
				pkgdb_close(db);
-
				sbuf_delete(sql);
-
				pkg_repos_free(repos);
-
				return(EPKG_FATAL);
-
			}
-

-
			if (sql_exec(db->sqlite, sbuf_get(sql)) != EPKG_OK) {
-
				sbuf_finish(sql);
-
				sbuf_delete(sql);
-
				pkgdb_close(db);
-
				pkg_repos_free(repos);
-
				return (EPKG_FATAL);
-
			}
-

-
			pkg_repos_free(repos);
		} else {
			/*
			 * Working on a single remote repository
modified pkg/update.c
@@ -100,9 +100,9 @@ exec_update(int argc, char **argv)
{
	char url[MAXPATHLEN];
	const char *packagesite = NULL;
+
	const char *repo_name;
+
	struct pkg_config_kv *repokv;
	int retcode = EPKG_OK;
-
	struct pkg_repos *repos = NULL;
-
	struct pkg_repos_entry *re = NULL;
	bool multi_repos = false;

	(void)argv;
@@ -141,26 +141,17 @@ exec_update(int argc, char **argv)
		retcode = update_from_remote_repo("repo", url);
	} else {
		/* multiple repositories */
-
		if (pkg_repos_new(&repos) != EPKG_OK)
-
			return (1);
-

-
		if (pkg_repos_load(repos) != EPKG_OK) {
-
			pkg_repos_free(repos);
-
			return (1);
-
		}
-

-
		while (pkg_repos_next(repos, &re) == EPKG_OK) {
-
			packagesite = pkg_repos_get_url(re);
+
		while (pkg_config_list(PKG_CONFIG_REPOS, &repokv) == EPKG_OK) {
+
			repo_name = pkg_config_kv_get(repokv, PKG_CONFIG_KV_KEY);
+
			packagesite = pkg_config_kv_get(repokv, PKG_CONFIG_KV_VALUE);

			if (packagesite[strlen(packagesite) - 1] == '/')
				snprintf(url, MAXPATHLEN, "%srepo.txz", packagesite);
			else
				snprintf(url, MAXPATHLEN, "%s/repo.txz", packagesite);

-
			retcode = update_from_remote_repo(pkg_repos_get_name(re), url);
+
			retcode = update_from_remote_repo(repo_name, url);
		}
-

-
		pkg_repos_free(repos);
	}

	return (retcode);