Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge remote-tracking branch 'upstream/master' and resolve conflicts
Marin Atanasov Nikolov committed 14 years ago
commit f279bf9bed9692ad6a92426ed8af98aa6747ea67
parent 1c5352f
28 files changed +225 -485
modified libpkg/Makefile
@@ -14,7 +14,6 @@ SRCS= pkg.c \
		pkg_delete.c \
		pkg_elf.c \
		pkg_event.c \
-
		pkg_error.c \
		pkg_jobs.c \
		pkg_manifest.c \
		pkg_ports.c \
modified libpkg/fetch.c
@@ -12,7 +12,6 @@

#include "pkg.h"
#include "pkg_event.h"
-
#include "pkg_error.h"

int
pkg_fetch_file(const char *url, const char *dest)
modified libpkg/pkg.c
@@ -1,5 +1,6 @@
#include <archive.h>
#include <archive_entry.h>
+
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
@@ -7,7 +8,6 @@

#include "pkg.h"
#include "pkg_event.h"
-
#include "pkg_error.h"
#include "pkg_private.h"
#include "pkg_util.h"

@@ -109,10 +109,7 @@ pkg_free(struct pkg *pkg)
pkg_t
pkg_type(struct pkg const * const pkg)
{
-
	if (pkg == NULL) {
-
		ERROR_BAD_ARG("pkg");
-
		return (PKG_NONE);
-
	}
+
	assert(pkg != NULL);

	return (pkg->type);
}
@@ -120,15 +117,8 @@ pkg_type(struct pkg const * const pkg)
const char *
pkg_get(struct pkg const * const pkg, const pkg_attr attr)
{
-
	if (pkg == NULL) {
-
		ERROR_BAD_ARG("pkg");
-
		return (NULL);
-
	}
-

-
	if (attr > PKG_NUM_FIELDS) {
-
		ERROR_BAD_ARG("attr");
-
		return (NULL);
-
	}
+
	assert(pkg != NULL);
+
	assert(attr <= PKG_NUM_FIELDS);

	if ((pkg->fields[attr].type & pkg->type) == 0)
		EMIT_PKG_ERROR("%s", "wrong usage of `attr` for this type of `pkg`");
@@ -141,18 +131,12 @@ pkg_set(struct pkg * pkg, pkg_attr attr, const char *value)
{
	struct sbuf **sbuf;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (attr > PKG_NUM_FIELDS)
-
		return (ERROR_BAD_ARG("attr"));
+
	assert(pkg != NULL);
+
	assert(attr <= PKG_NUM_FIELDS);
+
	assert(value != NULL || pkg->fields[attr].optional == 1);

-
	if (value == NULL) {
-
		if (pkg->fields[attr].optional == 1)
-
			value = "";
-
		else
-
			return (ERROR_BAD_ARG("value"));
-
	}
+
	if (value == NULL)
+
		value = "";

	sbuf = &pkg->fields[attr].value;

@@ -177,11 +161,8 @@ pkg_set_from_file(struct pkg *pkg, pkg_attr attr, const char *path)
	off_t size = 0;
	int ret = EPKG_OK;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (path == NULL)
-
		return (ERROR_BAD_ARG("path"));
+
	assert(pkg != NULL);
+
	assert(path != NULL);

	if ((ret = file_to_buffer(path, &buf, &size)) !=  EPKG_OK)
		return (ret);
@@ -196,10 +177,7 @@ pkg_set_from_file(struct pkg *pkg, pkg_attr attr, const char *path)
int64_t
pkg_flatsize(struct pkg *pkg)
{
-
	if (pkg == NULL) {
-
		ERROR_BAD_ARG("pkg");
-
		return (-1);
-
	}
+
	assert(pkg != NULL);

	return (pkg->flatsize);
}
@@ -215,10 +193,7 @@ pkg_setautomatic(struct pkg *pkg)
int
pkg_isautomatic(struct pkg *pkg)
{
-
	if (pkg == NULL) {
-
		ERROR_BAD_ARG("pkg");
-
		return (-1);
-
	}
+
	assert(pkg != NULL);

	return (pkg->automatic);
}
@@ -226,10 +201,7 @@ pkg_isautomatic(struct pkg *pkg)
int64_t
pkg_new_flatsize(struct pkg *pkg)
{
-
	if (pkg == NULL) {
-
		ERROR_BAD_ARG("pkg");
-
		return (-1);
-
	}
+
	assert(pkg != NULL);

	return (pkg->new_flatsize);
}
@@ -237,10 +209,7 @@ pkg_new_flatsize(struct pkg *pkg)
int64_t
pkg_new_pkgsize(struct pkg *pkg)
{
-
	if (pkg == NULL) {
-
		ERROR_BAD_ARG("pkg");
-
		return (-1);
-
	}
+
	assert(pkg != NULL);

	return (pkg->new_pkgsize);
}
@@ -248,11 +217,8 @@ pkg_new_pkgsize(struct pkg *pkg)
int
pkg_setflatsize(struct pkg *pkg, int64_t size)
{
-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (size < 0)
-
		return (ERROR_BAD_ARG("size"));
+
	assert(pkg != NULL);
+
	assert(size >= 0);

	pkg->flatsize = size;
	return (EPKG_OK);
@@ -261,11 +227,8 @@ pkg_setflatsize(struct pkg *pkg, int64_t size)
int
pkg_setnewflatsize(struct pkg *pkg, int64_t size)
{
-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (size <0)
-
		return (ERROR_BAD_ARG("size"));
+
	assert(pkg != NULL);
+
	assert(size >= 0);

	pkg->new_flatsize = size;

@@ -275,11 +238,8 @@ pkg_setnewflatsize(struct pkg *pkg, int64_t size)
int
pkg_setnewpkgsize(struct pkg *pkg, int64_t size)
{
-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (size <0)
-
		return (ERROR_BAD_ARG("size"));
+
	assert(pkg != NULL);
+
	assert(size >= 0);

	pkg->new_pkgsize = size;

@@ -289,8 +249,7 @@ pkg_setnewpkgsize(struct pkg *pkg, int64_t size)
int
pkg_deps(struct pkg *pkg, struct pkg_dep **d)
{
-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg != NULL);

	if (*d == NULL)
		*d = STAILQ_FIRST(&pkg->deps);
@@ -306,8 +265,7 @@ pkg_deps(struct pkg *pkg, struct pkg_dep **d)
int
pkg_rdeps(struct pkg *pkg, struct pkg_dep **d)
{
-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg != NULL);

	if (*d == NULL)
		*d = STAILQ_FIRST(&pkg->rdeps);
@@ -323,8 +281,7 @@ pkg_rdeps(struct pkg *pkg, struct pkg_dep **d)
int
pkg_files(struct pkg *pkg, struct pkg_file **f)
{
-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg != NULL);

	if (*f == NULL)
		*f = STAILQ_FIRST(&pkg->files);
@@ -340,8 +297,7 @@ pkg_files(struct pkg *pkg, struct pkg_file **f)
int
pkg_dirs(struct pkg *pkg, struct pkg_dir **d)
{
-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg != NULL);

	if (*d == NULL)
		*d = STAILQ_FIRST(&pkg->dirs);
@@ -357,8 +313,7 @@ pkg_dirs(struct pkg *pkg, struct pkg_dir **d)
int
pkg_conflicts(struct pkg *pkg, struct pkg_conflict **c)
{
-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg != NULL);

	if (*c == NULL)
		*c = STAILQ_FIRST(&pkg->conflicts);
@@ -374,8 +329,7 @@ pkg_conflicts(struct pkg *pkg, struct pkg_conflict **c)
int
pkg_scripts(struct pkg *pkg, struct pkg_script **s)
{
-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg != NULL);

	if (*s == NULL)
		*s = STAILQ_FIRST(&pkg->scripts);
@@ -391,8 +345,7 @@ pkg_scripts(struct pkg *pkg, struct pkg_script **s)
int
pkg_options(struct pkg *pkg, struct pkg_option **o)
{
-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg != NULL);

	if (*o == NULL)
		*o = STAILQ_FIRST(&pkg->options);
@@ -410,17 +363,10 @@ pkg_adddep(struct pkg *pkg, const char *name, const char *origin, const char *ve
{
	struct pkg_dep *d;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (name == NULL || name[0] == '\0')
-
		return (ERROR_BAD_ARG("name"));
-

-
	if (origin == NULL || origin[0] == '\0')
-
		return (ERROR_BAD_ARG("origin"));
-

-
	if (version == NULL || version[0] == '\0')
-
		return (ERROR_BAD_ARG("version"));
+
	assert(pkg != NULL);
+
	assert(name != NULL && name[0] != '\0');
+
	assert(origin != NULL && origin[0] != '\0');
+
	assert(version != NULL && version[0] != '\0');

	pkg_dep_new(&d);

@@ -438,17 +384,10 @@ pkg_addrdep(struct pkg *pkg, const char *name, const char *origin, const char *v
{
	struct pkg_dep *d;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (name == NULL || name[0] == '\0')
-
		return (ERROR_BAD_ARG("name"));
-

-
	if (origin == NULL || origin[0] == '\0')
-
		return (ERROR_BAD_ARG("origin"));
-

-
	if (version == NULL || version[0] == '\0')
-
		return (ERROR_BAD_ARG("version"));
+
	assert(pkg != NULL);
+
	assert(name != NULL && name[0] != '\0');
+
	assert(origin != NULL && origin[0] != '\0');
+
	assert(version != NULL && version[0] != '\0');

	pkg_dep_new(&d);

@@ -466,11 +405,8 @@ pkg_addfile(struct pkg *pkg, const char *path, const char *sha256)
{
	struct pkg_file *f;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (path == NULL || path[0] == '\0')
-
		return (ERROR_BAD_ARG("path"));
+
	assert(pkg != NULL);
+
	assert(path != NULL && path[0] != '\0');

	pkg_file_new(&f);

@@ -489,11 +425,8 @@ pkg_adddir(struct pkg *pkg, const char *path)
{
	struct pkg_dir *d = NULL;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (path == NULL || path[0] == '\0')
-
		return (ERROR_BAD_ARG("path"));
+
	assert(pkg != NULL);
+
	assert(path != NULL && path[0] != '\0');

	while (pkg_dirs(pkg, &d) == EPKG_OK) {
		if (strcmp(path, pkg_dir_path(d)) == 0) {
@@ -515,11 +448,8 @@ pkg_addconflict(struct pkg *pkg, const char *glob)
{
	struct pkg_conflict *c;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (glob == NULL || glob[0] == '\0')
-
		return (ERROR_BAD_ARG("glob"));
+
	assert(pkg != NULL);
+
	assert(glob != NULL && glob[0] != '\0');

	pkg_conflict_new(&c);
	sbuf_set(&c->glob, glob);
@@ -534,8 +464,7 @@ pkg_addscript(struct pkg *pkg, const char *data, pkg_script_t type)
{
	struct pkg_script *s;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg != NULL);

	pkg_script_new(&s);
	sbuf_set(&s->data, data);
@@ -555,11 +484,8 @@ pkg_addscript_file(struct pkg *pkg, const char *path)
	int ret = EPKG_OK;
	off_t sz = 0;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (path == NULL)
-
		return (ERROR_BAD_ARG("path"));
+
	assert(pkg != NULL);
+
	assert(path != NULL);

	if ((ret = file_to_buffer(path, &data, &sz)) != EPKG_OK)
		return (ret);
@@ -610,11 +536,8 @@ pkg_appendscript(struct pkg *pkg, const char *cmd, pkg_script_t type)
{
	struct pkg_script *s = NULL;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (cmd == NULL || cmd[0] == '\0')
-
		return (ERROR_BAD_ARG("cmd"));
+
	assert(pkg != NULL);
+
	assert(cmd != NULL && cmd[0] != '\0');

	while (pkg_scripts(pkg, &s) == EPKG_OK) {
		if (pkg_script_type(s) == type) {
@@ -643,14 +566,9 @@ pkg_addoption(struct pkg *pkg, const char *key, const char *value)
{
	struct pkg_option *o;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (key == NULL || key[0] == '\0')
-
		return (ERROR_BAD_ARG("opt"));
-

-
	if (value == NULL || value[0] == '\0')
-
		return (ERROR_BAD_ARG("value"));
+
	assert(pkg != NULL);
+
	assert(key != NULL && key[0] != '\0');
+
	assert(value != NULL && value[0] != '\0');

	pkg_option_new(&o);

@@ -798,8 +716,7 @@ pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, con
		{ NULL, 0 }
	};

-
	if (path == NULL)
-
		return (ERROR_BAD_ARG("path"));
+
	assert(path != NULL && path[0] != '\0');

	*a = archive_read_new();
	archive_read_support_compression_all(*a);
modified libpkg/pkg.h
@@ -590,21 +590,6 @@ int pkg_fetch_file(const char *url, const char *dest);
int ports_parse_plist(struct pkg *, char *);

/**
-
 * Return the last error number
-
 */
-
pkg_error_t pkg_error_number(void);
-

-
/**
-
 * Return the last error string
-
 */
-
const char * pkg_error_string(void);
-

-
/**
-
 * Behave like warn(3), but with the pkg error instead of errno
-
 */
-
void pkg_error_warn(const char *fmt, ...);
-

-
/**
 * @todo Document
 */
int pkg_copy_tree(struct pkg *, const char *src, const char *dest);
modified libpkg/pkg_add.c
@@ -1,5 +1,6 @@
#include <archive.h>
#include <archive_entry.h>
+
#include <assert.h>
#include <libgen.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -9,7 +10,6 @@

#include "pkg.h"
#include "pkg_event.h"
-
#include "pkg_error.h"
#include "pkg_private.h"

static int
@@ -93,8 +93,7 @@ pkg_add(struct pkgdb *db, const char *path)
	int retcode = EPKG_OK;
	int ret;

-
	if (path == NULL)
-
		return (ERROR_BAD_ARG("path"));
+
	assert(path != NULL);

	/*
	 * Open the package archive file, read all the meta files and set the
@@ -136,7 +135,8 @@ pkg_add(struct pkgdb *db, const char *path)

	basedir = dirname(path);
	if ((ext = strrchr(path, '.')) == NULL) {
-
		retcode = pkg_error_set(EPKG_FATAL, "%s has no extension", path);
+
		EMIT_PKG_ERROR("%s has no extension", path);
+
		retcode = EPKG_FATAL;
		goto cleanup;
	}

modified libpkg/pkg_config.c
@@ -10,7 +10,6 @@

#include "pkg.h"
#include "pkg_event.h"
-
#include "pkg_error.h"

struct _config {
	const char *key;
modified libpkg/pkg_create.c
@@ -2,6 +2,7 @@

#include <archive.h>
#include <archive_entry.h>
+
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <glob.h>
@@ -10,7 +11,7 @@
#include <fcntl.h>

#include "pkg.h"
-
#include "pkg_error.h"
+
#include "pkg_event.h"
#include "pkg_private.h"

static int pkg_create_from_dir(struct pkg *, const char *, struct packing *);
@@ -122,12 +123,13 @@ pkg_create_installed(const char *outdir, pkg_formats format, const char *rootdir
						 PKG_LOAD_DIRS | PKG_LOAD_SCRIPTS | PKG_LOAD_OPTIONS |
						 PKG_LOAD_MTREE;

-
	if (pkg->type != PKG_INSTALLED)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg->type == PKG_INSTALLED);

	pkg_archive = pkg_create_archive(outdir, pkg, format, required_flags);
-
	if (pkg_archive == NULL)
-
		return pkg_error_set(EPKG_FATAL, "unable to create archive"); /* XXX do better */
+
	if (pkg_archive == NULL) {
+
		EMIT_PKG_ERROR("%s", "unable to create archive");
+
		return (EPKG_FATAL);
+
	}

	pkg_create_from_dir(pkg, rootdir, pkg_archive);

modified libpkg/pkg_create_repo.c
@@ -15,7 +15,6 @@

#include "pkg.h"
#include "pkg_event.h"
-
#include "pkg_error.h"
#include "pkg_private.h"
#include "pkg_util.h"

@@ -108,12 +107,14 @@ pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *
	}

	if (sqlite3_prepare(sqlite, pkgsql, -1, &stmt_pkg, NULL) != SQLITE_OK) {
-
		retcode = ERROR_SQLITE(sqlite);
+
		ERROR_SQLITE(sqlite);
+
		retcode = EPKG_FATAL;
		goto cleanup;
	}

	if (sqlite3_prepare(sqlite, depssql, -1, &stmt_deps, NULL) != SQLITE_OK) {
-
		retcode = ERROR_SQLITE(sqlite);
+
		ERROR_SQLITE(sqlite);
+
		retcode = EPKG_FATAL;
		goto cleanup;
	}

@@ -169,7 +170,8 @@ pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *
		sqlite3_bind_text(stmt_pkg, 13, pkg_path, -1, SQLITE_STATIC);

		if (sqlite3_step(stmt_pkg) != SQLITE_DONE) {
-
			retcode = ERROR_SQLITE(sqlite);
+
			ERROR_SQLITE(sqlite);
+
			retcode = EPKG_FATAL;
			goto cleanup;
		}
		sqlite3_reset(stmt_pkg);
@@ -183,7 +185,8 @@ pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *
			sqlite3_bind_int64(stmt_deps, 4, package_id);

			if (sqlite3_step(stmt_deps) != SQLITE_DONE) {
-
				retcode = ERROR_SQLITE(sqlite);
+
				ERROR_SQLITE(sqlite);
+
				retcode = EPKG_FATAL;
				goto cleanup;
			}
			sqlite3_reset(stmt_deps);
modified libpkg/pkg_delete.c
@@ -1,6 +1,7 @@
#include <sys/stat.h>
#include <sys/types.h>

+
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
@@ -8,7 +9,6 @@

#include "pkg.h"
#include "pkg_event.h"
-
#include "pkg_error.h"
#include "pkg_private.h"
#include "pkg_util.h"

@@ -18,11 +18,8 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, int force)
	struct pkg_dep *rdep = NULL;
	int ret;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (db == NULL)
-
		return (ERROR_BAD_ARG("db"));
+
	assert(pkg != NULL);
+
	assert(db != NULL);

	/*
	 * Do not trust the existing entries as it may have changed if we
deleted libpkg/pkg_error.c
@@ -1,124 +0,0 @@
-
#include <err.h>
-
#include <errno.h>
-
#include <pthread.h>
-
#include <stdarg.h>
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-

-
#include "pkg.h"
-
#include "pkg_error.h"
-

-
struct pkg_error {
-
	pkg_error_t number;
-
	char *string;
-
};
-

-
pthread_once_t pkg_error_once = PTHREAD_ONCE_INIT;
-
pthread_key_t pkg_error_key;
-

-
static struct pkg_error * pkg_error_init(void);
-
static void pkg_error_init_once(void);
-
static void pkg_error_key_free(void *);
-

-
pkg_error_t
-
_pkg_error_set(pkg_error_t num, const char *fmt, ...)
-
{
-
	struct pkg_error *e;
-
	char *oldstring;
-
	va_list ap;
-

-
	e = pkg_error_init();
-

-
	oldstring = e->string;
-

-
	e->number = num;
-

-
	va_start(ap, fmt);
-
	vasprintf(&e->string, fmt, ap);
-
	va_end(ap);
-

-
	if (oldstring != NULL)
-
		free(oldstring);
-

-
	return (num);
-
}
-

-
pkg_error_t
-
pkg_error_number(void)
-
{
-
	struct pkg_error *e;
-

-
	e = pkg_error_init();
-

-
	return (e->number);
-
}
-

-
const char *
-
pkg_error_string(void)
-
{
-
	struct pkg_error *e;
-

-
	e = pkg_error_init();
-

-
	if (e->number == EPKG_OK)
-
		return ("(Empty error message)");
-
	else
-
		return (e->string);
-
}
-

-
void
-
pkg_error_warn(const char *fmt, ...)
-
{
-
	va_list ap;
-
	char *str = NULL;
-

-
	va_start(ap, fmt);
-
	vasprintf(&str, fmt, ap);
-
	va_end(ap);
-

-
	warnx("%s: %s\n", str, pkg_error_string());
-
	free(str);
-
}
-

-
static struct pkg_error *
-
pkg_error_init(void)
-
{
-
	struct pkg_error *e;
-

-
	if (pthread_once(&pkg_error_once, pkg_error_init_once) != 0)
-
		err(1, "pthread_once()");
-

-
	e = pthread_getspecific(pkg_error_key);
-

-
	if (e == NULL) {
-
		e = malloc(sizeof(struct pkg_error));
-

-
		if (e == NULL)
-
			err(1, "malloc()");
-

-
		e->number = EPKG_OK;
-
		e->string = NULL;
-

-
		if (pthread_setspecific(pkg_error_key, e) != 0)
-
			err(1, "pthread_setspecific()");
-
	}
-

-
	return (e);
-
}
-

-
static void
-
pkg_error_init_once(void)
-
{
-
	if (pthread_key_create(&pkg_error_key, pkg_error_key_free) != 0)
-
		err(1, "pthread_key_create()");
-
}
-

-
static void
-
pkg_error_key_free(void *data)
-
{
-
	struct pkg_error *e = data;
-

-
	free(e->string);
-
	free(e);
-
}
deleted libpkg/pkg_error.h
@@ -1,14 +0,0 @@
-
#ifndef _PKG_ERROR_H
-
#define _PKG_ERROR_H
-

-
#define	pkg_error_set _pkg_error_set
-

-
#define ERROR_BAD_ARG(name) \
-
	pkg_error_set(EPKG_FATAL, "Bad argument `%s` in %s", name, __FUNCTION__)
-

-
#define ERROR_SQLITE(db) \
-
	pkg_error_set(EPKG_FATAL, "%s (sqlite)", sqlite3_errmsg(db))
-

-
pkg_error_t _pkg_error_set(pkg_error_t, const char *, ...);
-

-
#endif
modified libpkg/pkg_jobs.c
@@ -5,17 +5,13 @@
#include "pkg.h"
#include "pkgdb.h"
#include "pkg_event.h"
-
#include "pkg_error.h"
#include "pkg_private.h"

int
pkg_jobs_new(struct pkg_jobs **j, pkg_jobs_t t, struct pkgdb *db)
{
-
	if (db == NULL)
-
		return (ERROR_BAD_ARG("db"));
-

-
	if (t == PKG_JOBS_INSTALL && db->type != PKGDB_REMOTE)
-
		return (ERROR_BAD_ARG("db"));
+
	assert(db != NULL);
+
	assert(t != PKG_JOBS_INSTALL || db->type == PKGDB_REMOTE);

	if((*j = calloc(1, sizeof(struct pkg_jobs))) == NULL) {
		EMIT_ERRNO("calloc", "pkg_jobs");
@@ -49,10 +45,8 @@ pkg_jobs_free(struct pkg_jobs *j)
int
pkg_jobs_add(struct pkg_jobs *j, struct pkg *pkg)
{
-
	if (j == NULL)
-
		return (ERROR_BAD_ARG("jobs"));
-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(j != NULL);
+
	assert(pkg != NULL);

	STAILQ_INSERT_TAIL(&j->jobs, pkg, next);

@@ -62,8 +56,7 @@ pkg_jobs_add(struct pkg_jobs *j, struct pkg *pkg)
int
pkg_jobs(struct pkg_jobs *j, struct pkg **pkg)
{
-
	if (j == NULL)
-
		return (ERROR_BAD_ARG("jobs"));
+
	assert(j != NULL);

	pkg_jobs_resolv(j);

@@ -230,8 +223,7 @@ pkg_jobs_resolv(struct pkg_jobs *j)
	struct pkg_jobs_node *n, *tmp;
	struct pkg *p;

-
	if (j == NULL)
-
		return (ERROR_BAD_ARG("jobs"));
+
	assert(j != NULL);

	if (j->resolved == 1)
		return (EPKG_OK);
modified libpkg/pkg_manifest.c
@@ -12,7 +12,6 @@

#include "pkg.h"
#include "pkg_event.h"
-
#include "pkg_error.h"
#include "pkg_util.h"
#include "pkg_private.h"

@@ -221,8 +220,7 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
	yaml_node_t *node;
	int retcode = EPKG_OK;

-
	if (buf == NULL)
-
		return (ERROR_BAD_ARG(buf));
+
	assert(buf != NULL);

	yaml_parser_initialize(&parser);
	yaml_parser_set_input_string(&parser, buf, strlen(buf));
modified libpkg/pkg_ports.c
@@ -1,5 +1,6 @@
#include <sys/stat.h>

+
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@@ -7,7 +8,6 @@

#include "pkg.h"
#include "pkg_event.h"
-
#include "pkg_error.h"
#include "pkg_private.h"

int
@@ -34,11 +34,8 @@ ports_parse_plist(struct pkg *pkg, char *plist)
	buf = NULL;
	p = NULL;

-
	if (pkg == NULL)
-
		return (ERROR_BAD_ARG("pkg"));
-

-
	if (plist == NULL)
-
		return (ERROR_BAD_ARG("plist"));
+
	assert(pkg != NULL);
+
	assert(plist != NULL);

	if ((ret = file_to_buffer(plist, &plist_buf, &sz)) != EPKG_OK)
		return (ret);
@@ -169,8 +166,7 @@ ports_parse_plist(struct pkg *pkg, char *plist)
					p = NULL;
				} else {
					flatsize += st.st_size;
-
					if (sha256_file(path, sha256) != 0)
-
						pkg_error_warn("can not compute sha256");
+
					sha256_file(path, sha256);
					p = sha256;
				}
				ret += pkg_addfile(pkg, path, p);
modified libpkg/pkg_repo.c
@@ -1,3 +1,4 @@
+
#include <assert.h>
#include <errno.h>
#include <libgen.h>
#include <string.h>
@@ -5,7 +6,6 @@

#include "pkg.h"
#include "pkg_event.h"
-
#include "pkg_error.h"
#include "pkg_private.h"

int
@@ -17,9 +17,8 @@ pkg_repo_fetch(struct pkg *pkg)
	char *url;
	int retcode = EPKG_OK;

-
	if ((pkg->type & PKG_REMOTE) != PKG_REMOTE &&
-
		(pkg->type & PKG_UPGRADE) != PKG_UPGRADE)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert((pkg->type & PKG_REMOTE) == PKG_REMOTE ||
+
		(pkg->type & PKG_UPGRADE) == PKG_UPGRADE);

	snprintf(dest, sizeof(dest), "%s/%s", pkg_config("PKG_CACHEDIR"),
			 pkg_get(pkg, PKG_REPOPATH));
@@ -30,7 +29,8 @@ pkg_repo_fetch(struct pkg *pkg)

	/* Create the dirs in cachedir */
	if ((path = dirname(dest)) == NULL) {
-
		retcode = pkg_error_set(EPKG_FATAL, "dirname(%s): %s", dest, strerror(errno));
+
		EMIT_ERRNO("dirname", dest);
+
		retcode = EPKG_FATAL;
		goto cleanup;
	}
	if ((retcode = mkdirs(path)) != 0)
modified libpkg/pkg_util.c
@@ -14,7 +14,6 @@

#include "pkg.h"
#include "pkg_event.h"
-
#include "pkg_error.h"
#include "pkg_util.h"

int
@@ -73,7 +72,7 @@ mkdirs(const char *_path)

		if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
			if (errno != EEXIST && errno != EISDIR) {
-
				pkg_error_set(EPKG_FATAL, "mkdir(%s): %s", path, strerror(errno));
+
				EMIT_ERRNO("mkdir", path);
				return (EPKG_FATAL);
			}

@@ -95,14 +94,9 @@ file_to_buffer(const char *path, char **buffer, off_t *sz)
	struct stat st;
	int retcode = EPKG_OK;

-
	if (path == NULL || path[0] == '\0')
-
		return (ERROR_BAD_ARG("path"));
-

-
	if (buffer == NULL)
-
		return (ERROR_BAD_ARG("buffer"));
-

-
	if (sz == NULL)
-
		return (ERROR_BAD_ARG("sz"));
+
	assert(path != NULL && path[0] != '\0');
+
	assert(buffer != NULL);
+
	assert(sz != NULL);

	if ((fd = open(path, O_RDONLY)) == -1) {
		EMIT_ERRNO("open", path);
modified libpkg/pkg_util.h
@@ -15,6 +15,9 @@ struct array {

#define STARTS_WITH(string, needle) (strncasecmp(string, needle, strlen(needle)) == 0)

+
#define ERROR_SQLITE(db) \
+
	EMIT_PKG_ERROR("sqlite: %s", sqlite3_errmsg(db))
+

int sbuf_set(struct sbuf **, const char *);
const char * sbuf_get(struct sbuf *);
void sbuf_reset(struct sbuf *);
modified libpkg/pkgdb.c
@@ -13,7 +13,6 @@

#include "pkg.h"
#include "pkg_event.h"
-
#include "pkg_error.h"
#include "pkg_private.h"
#include "pkgdb.h"
#include "pkg_util.h"
@@ -267,8 +266,10 @@ pkgdb_open(struct pkgdb **db, pkgdb_t type)
		}
	}

-
	if (sqlite3_open(localpath, &(*db)->sqlite) != SQLITE_OK)
-
		return (ERROR_SQLITE((*db)->sqlite));
+
	if (sqlite3_open(localpath, &(*db)->sqlite) != SQLITE_OK) {
+
		ERROR_SQLITE((*db)->sqlite);
+
		return (EPKG_FATAL);
+
	}

	if (type == PKGDB_REMOTE) {
		snprintf(remotepath, sizeof(remotepath), "%s/repo.sqlite", dbdir);
@@ -289,8 +290,10 @@ pkgdb_open(struct pkgdb **db, pkgdb_t type)

	/* If the database is missing we have to initialize it */
	if (retcode == -1)
-
		if ((retcode = pkgdb_init((*db)->sqlite)) != EPKG_OK)
-
			return (ERROR_SQLITE((*db)->sqlite));
+
		if ((retcode = pkgdb_init((*db)->sqlite)) != EPKG_OK) {
+
			ERROR_SQLITE((*db)->sqlite);
+
			return (EPKG_FATAL);
+
		}

	sqlite3_create_function((*db)->sqlite, "regexp", 2, SQLITE_ANY, NULL,
							pkgdb_regex_basic, NULL, NULL);
@@ -354,8 +357,7 @@ pkgdb_it_next(struct pkgdb_it *it, struct pkg **pkg_p, int flags)
	struct pkg *pkg;
	int ret;

-
	if (it == NULL)
-
		return (ERROR_BAD_ARG("it"));
+
	assert(it != NULL);

	switch (sqlite3_step(it->stmt)) {
	case SQLITE_ROW:
@@ -432,7 +434,8 @@ pkgdb_it_next(struct pkgdb_it *it, struct pkg **pkg_p, int flags)
	case SQLITE_DONE:
		return (EPKG_END);
	default:
-
		return (ERROR_SQLITE(it->db->sqlite));
+
		ERROR_SQLITE(it->db->sqlite);
+
		return (EPKG_FATAL);
	}
}

@@ -453,10 +456,7 @@ pkgdb_query(struct pkgdb *db, const char *pattern, match_t match)
	const char *comp = NULL;
	char *checkorigin = NULL;

-
	if (match != MATCH_ALL && pattern == NULL) {
-
		ERROR_BAD_ARG("pattern");
-
		return (NULL);
-
	}
+
	assert(match == MATCH_ALL || pattern != NULL);

	if (pattern != NULL)
		checkorigin = strchr(pattern, '/');
@@ -533,10 +533,7 @@ pkgdb_query_remote(struct pkgdb *db, const char *pattern)
			"AND NOT EXISTS (SELECT 1 FROM main.packages AS p "
			"WHERE p.origin = d.origin)";

-
	if (db == NULL || db->type != PKGDB_REMOTE) {
-
		ERROR_BAD_ARG("db");
-
		return (NULL);
-
	}
+
	assert(db != NULL && db->type == PKGDB_REMOTE);

	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
		ERROR_SQLITE(db->sqlite);
@@ -621,14 +618,15 @@ pkgdb_loaddeps(struct pkgdb *db, struct pkg *pkg)
	"WHERE p.origin = d.origin "
		"AND d.package_id = ?1;";

-
	if (pkg->type != PKG_INSTALLED)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg->type == PKG_INSTALLED);

	if (pkg->flags & PKG_LOAD_DEPS)
		return (EPKG_OK);

-
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
-
		return (ERROR_SQLITE(db->sqlite));
+
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
+
	}

	sqlite3_bind_int64(stmt, 1, pkg->rowid);

@@ -640,7 +638,8 @@ pkgdb_loaddeps(struct pkgdb *db, struct pkg *pkg)

	if (ret != SQLITE_DONE) {
		pkg_freedeps(pkg);
-
		return (ERROR_SQLITE(db->sqlite));
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
	}

	pkg->flags |= PKG_LOAD_DEPS;
@@ -658,14 +657,15 @@ pkgdb_loadrdeps(struct pkgdb *db, struct pkg *pkg)
		"WHERE p.rowid = d.package_id "
			"AND d.origin = ?1;";

-
	if (pkg->type != PKG_INSTALLED)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg->type == PKG_INSTALLED);

	if (pkg->flags & PKG_LOAD_RDEPS)
		return (EPKG_OK);

-
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
-
		return (ERROR_SQLITE(db->sqlite));
+
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
+
	}

	sqlite3_bind_text(stmt, 1, pkg_get(pkg, PKG_ORIGIN), -1, SQLITE_STATIC);

@@ -677,7 +677,8 @@ pkgdb_loadrdeps(struct pkgdb *db, struct pkg *pkg)

	if (ret != SQLITE_DONE) {
		pkg_freerdeps(pkg);
-
		return (ERROR_SQLITE(db->sqlite));
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
	}

	pkg->flags |= PKG_LOAD_RDEPS;
@@ -695,14 +696,15 @@ pkgdb_loadfiles(struct pkgdb *db, struct pkg *pkg)
		"WHERE package_id = ?1 "
		"ORDER BY PATH ASC";

-
	if (pkg->type != PKG_INSTALLED)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg->type == PKG_INSTALLED);

	if (pkg->flags & PKG_LOAD_FILES)
		return (EPKG_OK);

-
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
-
		return (ERROR_SQLITE(db->sqlite));
+
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
+
	}

	sqlite3_bind_int64(stmt, 1, pkg->rowid);

@@ -713,7 +715,8 @@ pkgdb_loadfiles(struct pkgdb *db, struct pkg *pkg)

	if (ret != SQLITE_DONE) {
		pkg_freefiles(pkg);
-
		return (ERROR_SQLITE(db->sqlite));
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
	}

	pkg->flags |= PKG_LOAD_FILES;
@@ -734,8 +737,10 @@ pkgdb_loaddirs(struct pkgdb *db, struct pkg *pkg)
	if (pkg->flags & PKG_LOAD_DIRS)
		return (EPKG_OK);

-
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
-
		return (ERROR_SQLITE(db->sqlite));
+
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
+
	}

	sqlite3_bind_text(stmt, 1, pkg_get(pkg, PKG_ORIGIN), -1, SQLITE_STATIC);

@@ -746,7 +751,8 @@ pkgdb_loaddirs(struct pkgdb *db, struct pkg *pkg)

	if (ret != SQLITE_DONE) {
		pkg_freedirs(pkg);
-
		return (ERROR_SQLITE(db->sqlite));
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
	}

	pkg->flags |= PKG_LOAD_DIRS;
@@ -763,14 +769,15 @@ pkgdb_loadconflicts(struct pkgdb *db, struct pkg *pkg)
		"FROM conflicts "
		"WHERE package_id = ?1;";

-
	if (pkg->type != PKG_INSTALLED)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg->type == PKG_INSTALLED);

	if (pkg->flags & PKG_LOAD_CONFLICTS)
		return (EPKG_OK);

-
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
-
		return (ERROR_SQLITE(db->sqlite));
+
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
+
	}

	sqlite3_bind_int64(stmt, 1, pkg->rowid);

@@ -781,7 +788,8 @@ pkgdb_loadconflicts(struct pkgdb *db, struct pkg *pkg)

	if (ret != SQLITE_DONE) {
		pkg_freeconflicts(pkg);
-
		return (ERROR_SQLITE(db->sqlite));
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
	}

	pkg->flags |= PKG_LOAD_CONFLICTS;
@@ -799,14 +807,15 @@ pkgdb_loadscripts(struct pkgdb *db, struct pkg *pkg)
		"FROM scripts "
		"WHERE package_id = ?1";

-
	if (pkg->type != PKG_INSTALLED)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg->type == PKG_INSTALLED);

	if (pkg->flags & PKG_LOAD_SCRIPTS)
		return (EPKG_OK);

-
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
-
		return (ERROR_SQLITE(db->sqlite));
+
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
+
	}

	sqlite3_bind_int64(stmt, 1, pkg->rowid);

@@ -817,7 +826,8 @@ pkgdb_loadscripts(struct pkgdb *db, struct pkg *pkg)

	if (ret != SQLITE_DONE) {
		pkg_freescripts(pkg);
-
		return (ERROR_SQLITE(db->sqlite));
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
	}

	pkg->flags |= PKG_LOAD_SCRIPTS;
@@ -834,14 +844,15 @@ pkgdb_loadoptions(struct pkgdb *db, struct pkg *pkg)
		"FROM options "
		"WHERE package_id = ?1";

-
	if (pkg->type != PKG_INSTALLED)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg->type == PKG_INSTALLED);

	if (pkg->flags & PKG_LOAD_OPTIONS)
		return (EPKG_OK);

-
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
-
		return (ERROR_SQLITE(db->sqlite));
+
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
+
	}

	sqlite3_bind_int64(stmt, 1, pkg->rowid);

@@ -853,7 +864,8 @@ pkgdb_loadoptions(struct pkgdb *db, struct pkg *pkg)

	if (ret != SQLITE_DONE) {
		pkg_freeoptions(pkg);
-
		return (ERROR_SQLITE(db->sqlite));
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
	}

	pkg->flags |= PKG_LOAD_OPTIONS;
@@ -871,14 +883,15 @@ pkgdb_loadmtree(struct pkgdb *db, struct pkg *pkg)
		"WHERE m.id = p.mtree_id "
			" AND p.id = ?1;";

-
	if (pkg->type != PKG_INSTALLED)
-
		return (ERROR_BAD_ARG("pkg"));
+
	assert(pkg->type == PKG_INSTALLED);

	if (pkg->flags & PKG_LOAD_MTREE)
		return (EPKG_OK);

-
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
-
		return (ERROR_SQLITE(db->sqlite));
+
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
+
	}

	sqlite3_bind_int64(stmt, 1, pkg->rowid);

@@ -891,8 +904,10 @@ pkgdb_loadmtree(struct pkgdb *db, struct pkg *pkg)

	sqlite3_finalize(stmt);

-
	if (ret != SQLITE_DONE)
-
		return (ERROR_SQLITE(db->sqlite));
+
	if (ret != SQLITE_DONE) {
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_OK);
+
	}

	pkg->flags |= PKG_LOAD_MTREE;
	return (EPKG_OK);
@@ -930,7 +945,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
	sqlite3_stmt *stmt_dirs = NULL;

	int ret;
-
	int retcode = EPKG_OK;
+
	int retcode = EPKG_FATAL;
	const char *path;
	int64_t package_id;
	char *errmsg;
@@ -981,7 +996,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
	 * Insert package record
	 */
	if (sqlite3_prepare_v2(s, sql_pkg, -1, &stmt_pkg, NULL) != SQLITE_OK) {
-
		retcode = ERROR_SQLITE(s);
+
		ERROR_SQLITE(s);
		goto cleanup;
	}
	sqlite3_bind_text(stmt_pkg, 1, pkg_get(pkg, PKG_ORIGIN), -1, SQLITE_STATIC);
@@ -1000,7 +1015,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
	sqlite3_bind_int(stmt_pkg, 14, pkg_isautomatic(pkg));

	if ((ret = sqlite3_step(stmt_pkg)) != SQLITE_DONE) {
-
		retcode = ERROR_SQLITE(s);
+
		ERROR_SQLITE(s);
		goto cleanup;
	}

@@ -1009,7 +1024,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
	 */

	if (sqlite3_prepare_v2(s, sql_sel_pkg, -1, &stmt_sel_pkg, NULL) != SQLITE_OK) {
-
		retcode = ERROR_SQLITE(s);
+
		ERROR_SQLITE(s);
		goto cleanup;
	}
	sqlite3_bind_text(stmt_sel_pkg, 1, pkg_get(pkg, PKG_ORIGIN), -1, SQLITE_STATIC);
@@ -1018,7 +1033,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
		package_id = sqlite3_column_int64(stmt_sel_pkg, 0);
		ret = SQLITE_DONE;
	} else {
-
		retcode = ERROR_SQLITE(s);
+
		ERROR_SQLITE(s);
		goto cleanup;
	}

@@ -1028,7 +1043,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)

	if (sqlite3_prepare_v2(s, sql_dep, -1, &stmt_dep, NULL) != SQLITE_OK) {

-
		retcode = ERROR_SQLITE(s);
+
		ERROR_SQLITE(s);
		goto cleanup;
	}

@@ -1039,7 +1054,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
		sqlite3_bind_int64(stmt_dep, 4, package_id);

		if ((ret = sqlite3_step(stmt_dep)) != SQLITE_DONE) {
-
			retcode = ERROR_SQLITE(s);
+
			ERROR_SQLITE(s);
			goto cleanup;
		}

@@ -1051,7 +1066,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
	 */

	if (sqlite3_prepare_v2(s, sql_conflict, -1, &stmt_conflict, NULL) != SQLITE_OK) {
-
		retcode = ERROR_SQLITE(s);
+
		ERROR_SQLITE(s);
		goto cleanup;
	}

@@ -1060,7 +1075,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
		sqlite3_bind_int64(stmt_conflict, 2, package_id);

		if ((ret = sqlite3_step(stmt_conflict)) != SQLITE_DONE) {
-
			retcode = ERROR_SQLITE(s);
+
			ERROR_SQLITE(s);
			goto cleanup;
		}

@@ -1072,7 +1087,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
	 */

	if (sqlite3_prepare_v2(s, sql_file, -1, &stmt_file, NULL) != SQLITE_OK) {
-
		retcode = ERROR_SQLITE(s);
+
		ERROR_SQLITE(s);
		goto cleanup;
	}

@@ -1086,9 +1101,9 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
			if (ret == SQLITE_CONSTRAINT) {
				    EMIT_PKG_ERROR("sqlite constraint violation on files.path:"
								   " %s", pkg_file_path(file));
-
				retcode = EPKG_FATAL;
-
			} else
-
				retcode = ERROR_SQLITE(s);
+
			} else {
+
				ERROR_SQLITE(s);
+
			}
			goto cleanup;
		}
		sqlite3_reset(stmt_file);
@@ -1099,7 +1114,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
	 */

	if (sqlite3_prepare_v2(s, sql_dir, -1, &stmt_dirs, NULL) != SQLITE_OK) {
-
		retcode = ERROR_SQLITE(s);
+
		ERROR_SQLITE(s);
		goto cleanup;
	}

@@ -1111,9 +1126,8 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
			if ( ret == SQLITE_CONSTRAINT) {
				EMIT_PKG_ERROR("sqlite: constraint violation on dirs.path: %s",
			 					pkg_dir_path(dir));
-
				retcode = EPKG_FATAL;
			} else
-
				retcode = ERROR_SQLITE(s);
+
				ERROR_SQLITE(s);
			goto cleanup;
		}
		sqlite3_reset(stmt_dirs);
@@ -1124,7 +1138,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
	 */

	if (sqlite3_prepare_v2(s, sql_script, -1, &stmt_script, NULL) != SQLITE_OK) {
-
		retcode = ERROR_SQLITE(s);
+
		ERROR_SQLITE(s);
		goto cleanup;
	}

@@ -1134,7 +1148,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
		sqlite3_bind_int64(stmt_script, 3, package_id);

		if (sqlite3_step(stmt_script) != SQLITE_DONE) {
-
			retcode = ERROR_SQLITE(s);
+
			ERROR_SQLITE(s);
			goto cleanup;
		}

@@ -1146,7 +1160,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
	 */

	if (sqlite3_prepare_v2(s, sql_option, -1, &stmt_option, NULL) != SQLITE_OK) {
-
		retcode = ERROR_SQLITE(s);
+
		ERROR_SQLITE(s);
		goto cleanup;
	}

@@ -1156,13 +1170,15 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
		sqlite3_bind_int64(stmt_option, 3, package_id);

		if (sqlite3_step(stmt_option) != SQLITE_DONE) {
-
			retcode = ERROR_SQLITE(s);
+
			ERROR_SQLITE(s);
			goto cleanup;
		}

		sqlite3_reset(stmt_option);
	}

+
	retcode = EPKG_OK;
+

	cleanup:

	if (stmt_pkg != NULL)
@@ -1224,29 +1240,30 @@ pkgdb_unregister_pkg(struct pkgdb *db, const char *origin)
	char *errmsg;
	const char sql[] = "DELETE FROM packages WHERE origin = ?1;";

-
	if (db == NULL)
-
		return (ERROR_BAD_ARG("db"));
+
	assert(db != NULL);
+
	assert(origin != NULL);

-
	if (origin == NULL)
-
		return (ERROR_BAD_ARG("origin"));
-

-
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt_del, NULL) != SQLITE_OK)
-
		return (ERROR_SQLITE(db->sqlite));
+
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt_del, NULL) != SQLITE_OK){
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
+
	}

	sqlite3_bind_text(stmt_del, 1, origin, -1, SQLITE_STATIC);

	ret = sqlite3_step(stmt_del);
	sqlite3_finalize(stmt_del);

-
	if (ret != SQLITE_DONE)
-
		return (ERROR_SQLITE(db->sqlite));
+
	if (ret != SQLITE_DONE) {
+
		ERROR_SQLITE(db->sqlite);
+
		return (EPKG_FATAL);
+
	}

	/* cleanup directories */
	ret = sqlite3_exec(db->sqlite, "DELETE from directories WHERE id NOT IN (SELECT DISTINCT directory_id FROM pkg_dirs_assoc);", NULL, NULL, &errmsg);
	if (ret != SQLITE_OK) {
-
		ret = pkg_error_set(EPKG_FATAL, "%s", errmsg);
+
		EMIT_PKG_ERROR("sqlite: %s", errmsg);
		sqlite3_free(errmsg);
-
		return (ret);
+
		return (EPKG_FATAL);
	}

	return (EPKG_OK);
@@ -1256,8 +1273,10 @@ static int get_pragma(sqlite3 *s, const char *sql, int64_t *res) {
	sqlite3_stmt *stmt;
	int ret;

-
	if (sqlite3_prepare_v2(s, sql, -1, &stmt, NULL) != SQLITE_OK)
-
		return (ERROR_SQLITE(s));
+
	if (sqlite3_prepare_v2(s, sql, -1, &stmt, NULL) != SQLITE_OK) {
+
		ERROR_SQLITE(s);
+
		return (EPKG_OK);
+
	}

	ret = sqlite3_step(stmt);

@@ -1266,8 +1285,10 @@ static int get_pragma(sqlite3 *s, const char *sql, int64_t *res) {

	sqlite3_finalize(stmt);

-
	if (ret != SQLITE_ROW)
-
		return (ERROR_SQLITE(s));
+
	if (ret != SQLITE_ROW) {
+
		ERROR_SQLITE(s);
+
		return (EPKG_FATAL);
+
	}

	return (EPKG_OK);
}
@@ -1280,8 +1301,7 @@ pkgdb_compact(struct pkgdb *db)
	char *errmsg;
	int retcode = EPKG_OK;

-
	if (db == NULL)
-
		return (ERROR_BAD_ARG("db"));
+
	assert(db != NULL);

	if (get_pragma(db->sqlite, "PRAGMA page_count;", &page_count) != EPKG_OK)
		return (EPKG_FATAL);
@@ -1385,16 +1405,13 @@ pkgdb_rquery(struct pkgdb *db, const char *pattern, match_t match, unsigned int
	sqlite3_stmt *stmt = NULL;
	struct sbuf *sql = sbuf_new_auto();

+
	assert(pattern != NULL && pattern[0] != '\0');
+

	if (db->type != PKGDB_REMOTE) {
		EMIT_PKG_ERROR("%s", "remote database not attached (misuse)");
		return (NULL);
	}

-
	if (pattern == NULL) {
-
		ERROR_BAD_ARG("pattern");
-
		return (NULL);
-
	}
-

	sbuf_cat(sql, "SELECT p.rowid, p.origin, p.name, p.version, p.comment, "
			"p.desc, p.arch, p.arch, p.osversion, p.maintainer, p.www, "
			"p.flatsize, p.pkgsize, p.cksum, p.path FROM remote.packages AS p WHERE ");
modified libpkg/scripts.c
@@ -1,6 +1,7 @@
-
#include <pkg.h>
-
#include <pkg_private.h>
-
#include <pkg_error.h>
+
#include <assert.h>
+

+
#include "pkg.h"
+
#include "pkg_private.h"

int
pkg_script_run(struct pkg *pkg, pkg_script_t type)
@@ -29,8 +30,7 @@ pkg_script_run(struct pkg *pkg, pkg_script_t type)
			break;
	}

-
	if (map[i].a != type)
-
		return (ERROR_BAD_ARG("type"));
+
	assert(map[i].a == type);

	while (pkg_scripts(pkg, &script) == EPKG_OK) {

modified pkg/add.c
@@ -60,7 +60,6 @@ exec_add(int argc, char **argv)
		if (is_url(argv[i]) == EPKG_OK) {
			snprintf(path, sizeof(path), "./%s", basename(argv[i]));
			if ((retcode = pkg_fetch_file(argv[i], path)) != EPKG_OK) {
-
				pkg_error_warn("can not fetch %s", argv[i]);
				continue;
			}
			file = path;
@@ -68,7 +67,6 @@ exec_add(int argc, char **argv)
			file = argv[i];

		if (pkg_add(db, file) != EPKG_OK) {
-
			pkg_error_warn("can not install %s", file);
			continue;
		}
	}
modified pkg/autoremove.c
@@ -95,7 +95,6 @@ exec_autoremove(int argc, char **argv)
		while ((retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
			if (pkg_delete(pkg, db, 0) != EPKG_OK) {
				retcode++;
-
				pkg_error_warn("can not delete %s-%s", pkg_get(pkg, PKG_ORIGIN));
			}
		}

modified pkg/create.c
@@ -31,7 +31,6 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt, const
					  PKG_LOAD_MTREE;

	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
-
		pkg_error_warn("can not open database");
		pkgdb_close(db);
		return (EX_IOERR);
	}
@@ -39,28 +38,24 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt, const
	if (match != MATCH_ALL) {
		for (i = 0;i < argc; i++) {
			if ((it = pkgdb_query(db, argv[i], match)) == NULL) {
-
				pkg_error_warn("can not query database");
				goto cleanup;
			}
			while ((ret = pkgdb_it_next(it, &pkg, query_flags)) == EPKG_OK) {
				printf("Creating package for %s-%s\n", pkg_get(pkg, PKG_NAME),
				    pkg_get(pkg, PKG_VERSION));
				if (pkg_create_installed(outdir, fmt, rootdir, pkg) != EPKG_OK) {
-
					pkg_error_warn("can not create package");
					retcode++;
				}
			}
		}
	} else {
		if ((it = pkgdb_query(db, NULL, match)) == NULL) {
-
			pkg_error_warn("can not query database");
			goto cleanup;
		}
		while ((ret = pkgdb_it_next(it, &pkg, query_flags)) == EPKG_OK) {
			printf("Creating package for %s-%s\n", pkg_get(pkg, PKG_NAME),
					pkg_get(pkg, PKG_VERSION));
			if (pkg_create_installed(outdir, fmt, rootdir, pkg) != EPKG_OK) {
-
				pkg_error_warn("can not create package");
				retcode++;
			}
		}
@@ -68,7 +63,6 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt, const

cleanup:
	if (ret != EPKG_END) {
-
		pkg_error_warn("can not iterate over results");
		retcode++;
	}

modified pkg/delete.c
@@ -58,7 +58,6 @@ exec_delete(int argc, char **argv)
	}
	
	if ((retcode = pkgdb_open(&db, PKGDB_DEFAULT)) != EPKG_OK) {
-
		pkg_error_warn("can not open database");
		goto cleanup;
	}

@@ -66,12 +65,10 @@ exec_delete(int argc, char **argv)
		origin = argv[0];

	if ((retcode = pkg_jobs_new(&jobs, PKG_JOBS_DEINSTALL, db)) != EPKG_OK) {
-
		pkg_error_warn("cant create jobs");
		goto cleanup;
	}

	if ((it = pkgdb_query(db, origin, match)) == NULL) {
-
		pkg_error_warn("Can not query database");
		retcode = EPKG_FATAL;
		goto cleanup;
	}
@@ -82,17 +79,14 @@ exec_delete(int argc, char **argv)
	}

	if (retcode != EPKG_END) {
-
		pkg_error_warn("can not iterate over results");
		goto cleanup;
	}

	if ((retcode = pkg_jobs_apply(jobs, force)) != EPKG_OK) {
-
		pkg_error_warn("cant deinstall");
		goto cleanup;
	}

-
	if ((retcode = pkgdb_compact(db)) != EPKG_OK)
-
		pkg_error_warn("can not compact database");
+
	retcode = pkgdb_compact(db);

	cleanup:
	pkgdb_it_free(it);
modified pkg/info.c
@@ -282,7 +282,6 @@ exec_info(int argc, char **argv)
				print_info(pkg, opt);
		}
		if (ret != EPKG_END) {
-
			pkg_error_warn("can not iterate over results");
			retcode = -1;
		}

modified pkg/install.c
@@ -44,15 +44,13 @@ exec_install(int argc, char **argv)
	}

	if (pkg_jobs_new(&jobs, PKG_JOBS_INSTALL, db) != EPKG_OK) {
-
		pkg_error_warn("pkg_jobs_new()");
		retcode = EPKG_FATAL;
		goto cleanup;
	}

	for (i = 1; i < argc; i++) {
		if ((pkg = pkgdb_query_remote(db, argv[i])) == NULL) {
-
			retcode = pkg_error_number();
-
			pkg_error_warn("can query the database");
+
			retcode = EPKG_FATAL;
			goto cleanup;
		}

@@ -66,8 +64,7 @@ exec_install(int argc, char **argv)
		printf("%s-%s\n", pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION));
	}

-
	if (pkg_jobs_apply(jobs, 0) != EPKG_OK)
-
		pkg_error_warn("can not install");
+
	retcode = pkg_jobs_apply(jobs, 0);

	cleanup:
	pkgdb_close(db);
modified pkg/register.c
@@ -135,21 +135,20 @@ exec_register(int argc, char **argv)
	}

	snprintf(fpath, MAXPATHLEN, "%s/+DESC", mdir);
-
	if (pkg_set_from_file(pkg, PKG_DESC, fpath) != EPKG_OK)
-
		pkg_error_warn("");
+
	pkg_set_from_file(pkg, PKG_DESC, fpath);

	snprintf(fpath, MAXPATHLEN, "%s/+DISPLAY", mdir);
-
	if (access(fpath, F_OK) == 0 && pkg_set_from_file(pkg, PKG_MESSAGE, fpath) != EPKG_OK)
-
		pkg_error_warn("");
+
	if (access(fpath, F_OK) == 0)
+
		 pkg_set_from_file(pkg, PKG_MESSAGE, fpath);

	snprintf(fpath, MAXPATHLEN, "%s/+MTREE_DIRS", mdir);
-
	if (access(fpath, F_OK) == 0 && pkg_set_from_file(pkg, PKG_MTREE, fpath) != EPKG_OK)
-
		pkg_error_warn("");
+
	if (access(fpath, F_OK) == 0)
+
		pkg_set_from_file(pkg, PKG_MTREE, fpath);

	for (i = 0; scripts[i] != NULL; i++) {
		snprintf(fpath, MAXPATHLEN, "%s/%s", mdir, scripts[i]);
-
		if (access(fpath, F_OK) == 0 && pkg_addscript_file(pkg, fpath) != EPKG_OK)
-
			pkg_error_warn("");
+
		if (access(fpath, F_OK) == 0)
+
			pkg_addscript_file(pkg, fpath);
	}

	/* if www is not given then try to determine it from description */
modified pkg/search.c
@@ -62,13 +62,11 @@ exec_search(int argc, char **argv)
	pattern = argv[0];

	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {
-
		pkg_error_warn("can not open database");
		retcode = EPKG_FATAL;
		goto cleanup;
	}

	if ((it = pkgdb_rquery(db, pattern, match, field)) == NULL) {
-
		pkg_error_warn("can not query database");
		retcode = EPKG_FATAL;
		goto cleanup;
	}
modified pkg/which.c
@@ -34,7 +34,6 @@ exec_which(int argc, char **argv)
	}

	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
-
		pkg_error_warn("can not open database");
		pkgdb_close(db);
		return (EX_IOERR);
	}