Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
More errors reporting in the CLI!
jlaffaye committed 15 years ago
commit 67c2d6bf655cbb8dbe0bfed4dd509d21e751bf8c
parent dbcf55729b46dfd7b776db553afddc7233f88014
15 files changed +89 -44
modified libpkg/pkg.c
@@ -254,7 +254,7 @@ pkg_conflicts(struct pkg *pkg)
}

int
-
pkg_open(const char *path, struct pkg **pkg_p, int query_flags)
+
pkg_open(const char *path, struct pkg **pkg_p)
{
	struct archive *a;
	struct archive_entry *ae;
@@ -277,7 +277,6 @@ pkg_open(const char *path, struct pkg **pkg_p, int query_flags)
		file_fetch(path, "/tmp/bla");
		path = "/tmp/bla";
	}
-
	(void)query_flags;

	a = archive_read_new();
	archive_read_support_compression_all(a);
modified libpkg/pkg.h
@@ -156,7 +156,7 @@ void pkg_free(struct pkg *);
 * NULL pointer, the function allocate a new pkg using pkg_new().
 * @param flags Unused.
 */
-
int pkg_open(const char *path, struct pkg **p, int flags);
+
int pkg_open(const char *path, struct pkg **p);

pkg_t pkg_type(struct pkg *);

modified libpkg/pkg_add.c
@@ -43,6 +43,7 @@ pkg_extract(const char *path)
	return (EPKG_OK);
}

+
/* TODO: take a path to the package archive instead of a pkg */
int
pkg_add(struct pkgdb *db, struct pkg *pkg)
{
modified libpkg/pkg_create.c
@@ -18,6 +18,8 @@ static const char * pkg_create_set_format(struct archive *, pkg_formats);
static int pkg_create_from_dir(struct pkg *, const char *, struct archive *);
static int pkg_create_append_buffer(struct archive *, struct archive_entry *, const char *, const char *);

+
/* TODO: error reporting */
+

static int
pkg_create_append_buffer(struct archive *a, struct archive_entry *e, const char *buf, const char *name)
{
@@ -160,10 +162,9 @@ pkg_create(const char *mpath, pkg_formats format, const char *outdir, const char
	archive_write_close(pkg_archive);
	archive_write_finish(pkg_archive);

-
	return (0);
+
	return (EPKG_OK);
}

-

static const char *
pkg_create_set_format(struct archive *pkg_archive, pkg_formats format)
{
modified libpkg/pkg_delete.c
@@ -20,8 +20,9 @@ dircmp(char *path, struct array *a)
			return (1);

	return (0);
-
} 
+
}

+
/* TODO: take an origin and not a pkg */
int
pkg_delete(struct pkg *pkg, struct pkgdb *db, int force)
{
modified libpkg/pkg_private.h
@@ -29,7 +29,7 @@ struct pkg {
	struct array scripts;
	struct array exec;
	struct array options;
-
	const char *path;
+
	const char *path; /* TODO: remove */
	pkg_t type;
};

modified libpkg/pkg_repo.c
@@ -11,6 +11,8 @@
#include "pkg_private.h"
#include "pkg_util.h"

+
/* TODO: error reporting #@! */
+

int
pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *data)
{
@@ -99,7 +101,7 @@ pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *
				strcmp(ext, ".tar") != 0)
			continue;

-
		if (pkg_open(ent->fts_path, &pkg, 0) != EPKG_OK)
+
		if (pkg_open(ent->fts_path, &pkg) != EPKG_OK)
			continue;

		if (progress != NULL)
modified libpkg/pkgdb.c
@@ -272,7 +272,8 @@ pkgdb_it_next_pkg(struct pkgdb_it *it, struct pkg **pkg_p, int flags)
	struct pkg_option *o;
	struct pkgdb_it *i;

-
	if (it->type != IT_PKG)
+

+
	if (it == NULL || it->type != IT_PKG)
		return (ERROR_BAD_ARG("it"));

	switch (sqlite3_step(it->stmt)) {
@@ -393,7 +394,7 @@ pkgdb_it_next_conflict(struct pkgdb_it *it, struct pkg_conflict **c_p)
{
	struct pkg_conflict *c;

-
	if (it->type != IT_CONFLICT)
+
	if (it == NULL || it->type != IT_CONFLICT)
		return (ERROR_BAD_ARG("it"));

	switch (sqlite3_step(it->stmt)) {
@@ -419,7 +420,7 @@ pkgdb_it_next_file(struct pkgdb_it *it, struct pkg_file **file_p)
{
	struct pkg_file *file;

-
	if (it->type != IT_FILE)
+
	if (it == NULL || it->type != IT_FILE)
		return (ERROR_BAD_ARG("it"));

	switch (sqlite3_step(it->stmt)) {
@@ -445,7 +446,7 @@ pkgdb_it_next_exec(struct pkgdb_it *it, struct pkg_exec **exec_p)
{
	struct pkg_exec *exec;

-
	if (it->type != IT_EXEC)
+
	if (it == NULL || it->type != IT_EXEC)
		return (ERROR_BAD_ARG("it"));

	switch (sqlite3_step(it->stmt)) {
@@ -471,7 +472,7 @@ pkgdb_it_next_script (struct pkgdb_it *it, struct pkg_script **script_p)
{
	struct pkg_script *script;

-
	if (it->type != IT_SCRIPT)
+
	if (it == NULL || it->type != IT_SCRIPT)
		return (ERROR_BAD_ARG("it"));

	switch (sqlite3_step(it->stmt)) {
@@ -497,7 +498,7 @@ pkgdb_it_next_option (struct pkgdb_it *it, struct pkg_option **option_p)
{
	struct pkg_option *option;

-
	if (it->type != IT_OPTION)
+
	if (it == NULL || it->type != IT_OPTION)
		return (ERROR_BAD_ARG("it"));

	switch (sqlite3_step(it->stmt)) {
modified pkg/add.c
@@ -29,20 +29,22 @@ exec_add(int argc, char **argv)
		return (-1);
	}

-
	if (pkg_open(argv[1], &pkg, 0) != EPKG_OK) {
-
		pkg_error_warn("%s", argv[1]);
+
	if (pkg_open(argv[1], &pkg) != EPKG_OK) {
+
		pkg_error_warn("can not open file %s", argv[1]);
		return (-1);
	}

	if (pkgdb_open(&db) != EPKG_OK) {
-
		pkg_error_warn("Can not open database");
+
		pkg_error_warn("can not open database");
		pkgdb_close(db);
		return (-1);
	}

+
	/* TODO: all the following stuff should be into libpkg */
+

	/* check if already installed */
	if ((it = pkgdb_query(db, pkg_get(pkg, PKG_ORIGIN), MATCH_EXACT)) == NULL) {
-
		pkg_error_warn("");
+
		pkg_error_warn("can not query the database");
		return (-1);
	}

@@ -74,7 +76,7 @@ exec_add(int argc, char **argv)
	}

	if (pkg_add(db, pkg) != EPKG_OK)
-
		pkg_error_warn("Can not install %s", argv[1]);
+
		pkg_error_warn("can not install %s", argv[1]);

	pkgdb_close(db);
	pkg_free(pkg);
modified pkg/create.c
@@ -42,6 +42,8 @@ exec_create(int argc, char **argv)
	pkg_formats fmt;
	char mpath[MAXPATHLEN];
	char ch;
+
	int retcode = 0;
+
	int ret;

	while ((ch = getopt(argc, argv, "agxXf:r:m:o:")) != -1) {
		switch (ch) {
@@ -94,7 +96,7 @@ exec_create(int argc, char **argv)
		else if (strcmp(format, "tar") == 0)
			fmt = TAR;
		else {
-
			warnx("Unknown format %s, using txz", format);
+
			warnx("unknown format %s, using txz", format);
			fmt = TXZ;
		}
	}
@@ -102,27 +104,43 @@ exec_create(int argc, char **argv)
	if (manifestdir == NULL) {
		/* create package from local db */
		if (pkgdb_open(&db) != EPKG_OK) {
-
			pkg_error_warn("Can not open database");
+
			pkg_error_warn("can not open database");
			pkgdb_close(db);
			return (-1);
		}

		if ((it = pkgdb_query(db, argv[0], match)) == NULL) {
-
			pkg_error_warn("");
+
			pkg_error_warn("can not query database");
			return (-1);
		}

		pkg_new(&pkg);
-
		while (pkgdb_it_next_pkg(it, &pkg, PKG_ALL) == EPKG_OK) {
-
			printf("Creating package for %s-%s\n", pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION));
-
			pkg_create(NULL, fmt, outdir, rootdir, pkg);
+
		while ((ret = pkgdb_it_next_pkg(it, &pkg, PKG_ALL)) == EPKG_OK) {
+
			printf("Creating package for %s-%s\n", pkg_get(pkg, PKG_NAME),
+
				   pkg_get(pkg, PKG_VERSION));
+

+
			if (pkg_create(NULL, fmt, outdir, rootdir, pkg) != EPKG_OK) {
+
				pkg_error_warn("can not create package");
+
				retcode++;
+
			}
		}
+

		pkg_free(pkg);
		pkgdb_it_free(it);
		pkgdb_close(db);
+

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

	} else {
		snprintf(mpath, sizeof(mpath), "%s/+MANIFEST", manifestdir);
-
		pkg_create(mpath, fmt, outdir, rootdir, NULL);
+
		if (pkg_create(mpath, fmt, outdir, rootdir, NULL) != EPKG_OK) {
+
			pkg_error_warn("can not create package");
+
			retcode++;
+
		}
	}
-
	return (0);
+

+
	return (retcode);
}
modified pkg/delete.c
@@ -23,6 +23,8 @@ exec_delete(int argc, char **argv)
	match_t match = MATCH_EXACT;
	char *origin = NULL;
	char ch;
+
	int ret;
+
	int flags = PKG_BASIC|PKG_FILES|PKG_RDEPS;
	int force = 0;
	int retcode = 0;

@@ -46,7 +48,7 @@ exec_delete(int argc, char **argv)
	}

	if (pkgdb_open(&db) != EPKG_OK) {
-
		pkg_error_warn("Can not open database");
+
		pkg_error_warn("can not open database");
		pkgdb_close(db);
		return (-1);
	}
@@ -54,18 +56,25 @@ exec_delete(int argc, char **argv)
	if (argc == 1)
		origin = argv[0];

-
	it = pkgdb_query(db, origin, match);
+
	if ((it = pkgdb_query(db, origin, match)) == NULL) {
+
		pkg_error_warn("Can not query database");
+
		return (1);
+
	}

	pkg_new(&pkg);
-
	while (pkgdb_it_next_pkg(it, &pkg, PKG_BASIC|PKG_FILES|PKG_RDEPS) ==
-
		   EPKG_OK) {
+
	while ((ret = pkgdb_it_next_pkg(it, &pkg, flags)) == EPKG_OK) {
		if (pkg_delete(pkg, db, force) != EPKG_OK) {
			retcode++;
-
			pkg_error_warn("Can not delete %s", pkg_get(pkg, PKG_ORIGIN));
+
			pkg_error_warn("can not delete %s", pkg_get(pkg, PKG_ORIGIN));
		}
	}
	pkg_free(pkg);

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

	pkgdb_it_free(it);
	pkgdb_close(db);
	return (retcode);
modified pkg/info.c
@@ -126,21 +126,21 @@ exec_info(int argc, char **argv)

	/* if the last argument is a file then query directly the file */
	if (argc == 1 && access(argv[0], F_OK) == 0) {
-
		if (pkg_open(argv[0], &pkg, query_flags) != EPKG_OK) {
-
			warnx("Can not read package %s", argv[0]);
+
		if (pkg_open(argv[0], &pkg) != EPKG_OK) {
+
			warnx("can not read package %s", argv[0]);
			return (-1);
		}
		return (query_pkg(pkg, opt));
	}

	if (pkgdb_open(&db) != EPKG_OK) {
-
		pkg_error_warn("Can not open database");
+
		pkg_error_warn("can not open database");
		pkgdb_close(db);
		return (-1);
	}

	if ((it = pkgdb_query(db, argv[0], match)) == NULL) {
-
		pkg_error_warn("");
+
		pkg_error_warn("can not query database");
		return (-1);
	}

@@ -206,7 +206,7 @@ exec_info(int argc, char **argv)
	pkg_free(pkg);

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

modified pkg/register.c
@@ -161,7 +161,7 @@ exec_register(int argc, char **argv)
		free(plist);

	if (pkgdb_open(&db) != EPKG_OK) {
-
		pkg_error_warn("Can not open database");
+
		pkg_error_warn("can not open database");
		return (-1);
	}

@@ -171,7 +171,7 @@ exec_register(int argc, char **argv)
	compute_flatsize(pkg);

	if (pkgdb_register_pkg(db, pkg) != EPKG_OK) {
-
		pkg_error_warn("Can not register package");
+
		pkg_error_warn("can not register package");
		retcode = 1;
	}

modified pkg/repo.c
@@ -39,11 +39,18 @@ progress(struct pkg *pkg, void *data) {
int
exec_repo(int argc, char **argv)
{
-
	int len=0;
+
	int ret;
+
	int len = 0;
+

	if (argc != 2) {
		usage_repo();
		return (EX_USAGE);
	}

-
	return (pkg_create_repo(argv[1], progress, &len));
+
	ret = pkg_create_repo(argv[1], progress, &len);
+

+
	if (ret != EPKG_OK)
+
		pkg_error_warn("can not create repository");
+

+
	return (ret);
}
modified pkg/which.c
@@ -26,6 +26,7 @@ exec_which(int argc, char **argv)
	char pathabs[MAXPATHLEN];
	char pathabsdir[MAXPATHLEN];
	int retcode = 1;
+
	int ret;

	if (argc != 2) {
		usage_which();
@@ -33,7 +34,7 @@ exec_which(int argc, char **argv)
	}

	if (pkgdb_open(&db) != EPKG_OK) {
-
		pkg_error_warn("Can not open database");
+
		pkg_error_warn("can not open database");
		pkgdb_close(db);
		return (-1);
	}
@@ -42,15 +43,18 @@ exec_which(int argc, char **argv)
	snprintf(pathabs, sizeof(pathabs), "%s/%s", pathabsdir, basename(argv[1]));

	if ((it = pkgdb_query_which(db, pathabs)) == NULL) {
-
		pkg_error_warn("");
+
		pkg_error_warn("can not query database");
		return (-1);
	}

	pkg_new(&pkg);
-
	if (pkgdb_it_next_pkg(it, &pkg, PKG_BASIC) == EPKG_OK) {
+
	if (( ret = pkgdb_it_next_pkg(it, &pkg, PKG_BASIC)) == EPKG_OK) {
		retcode = 0;
		printf("%s was installed by package %s-%s\n", pathabs, pkg_get(pkg, PKG_NAME),
			   pkg_get(pkg, PKG_VERSION));
+
	} else if (ret != EPKG_END) {
+
		pkg_error_warn("can not iterate over results");
+
		retcode = -1;
	}
	pkg_free(pkg);
	pkgdb_it_free(it);