Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Better handling of failure in case we can't create local db
Baptiste Daroussin committed 14 years ago
commit 35c2882a4f5b9fb2c36e84024489ebc75eb79b07
parent 29842acef13d3522ee38f465986f3f9b6ab1a995
4 files changed +35 -9
modified libpkg/pkg.h
@@ -237,6 +237,10 @@ typedef enum {
	 * Can not install the package because some dependencies are unresolved.
	 */
	EPKG_DEPENDENCY,
+
	/**
+
	 * Can not create local database
+
	 */
+
	EPKG_ENODB,
} pkg_error_t;

/**
modified libpkg/pkgdb.c
@@ -453,14 +453,14 @@ pkgdb_open(struct pkgdb **db_p, pkgdb_t type)

	if (eaccess(localpath, R_OK) != 0) {
		if (errno != ENOENT) {
-
			pkg_emit_errno("Unable to create local database ", localpath);
+
			/*pkg_emit_errno("Unable to create local database ", localpath);*/
			pkgdb_close(db);
-
			return (EPKG_FATAL);
+
			return (EPKG_ENODB);
		} else if (eaccess(dbdir, W_OK) != 0) {
			/* If we need to create the db but can not write to it, fail early */
-
			pkg_emit_errno("Unable to create local database ", dbdir);
+
			/*pkg_emit_errno("Unable to create local database ", dbdir);*/
			pkgdb_close(db);
-
			return (EPKG_FATAL);
+
			return (EPKG_ENODB);
		} else {
			create = true;
		}
modified pkg/info.c
@@ -138,10 +138,23 @@ exec_info(int argc, char **argv)
		return (0);
	}

-
	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
-
		return (EX_IOERR);
+
	ret = pkgdb_open(&db, PKGDB_DEFAULT);
+
	if (ret == EPKG_ENODB) {
+
		if (geteuid() == 0)
+
			err(EX_IOERR, "Unable to create local database");
+

+
		if (match == MATCH_ALL)
+
			return (EXIT_SUCCESS);
+

+
		if ((opt & INFO_QUIET) == 0)
+
			printf("No package installed\n");
+

+
		return (EXIT_FAILURE);
	}

+
	if (ret != EPKG_OK)
+
		return (EX_IOERR);
+

	i = 0;
	do {
		pkgname = argv[i];
modified pkg/query.c
@@ -1,6 +1,7 @@
#include <sys/types.h>
#include <sys/sbuf.h>

+
#include <err.h>
#include <inttypes.h>
#include <libutil.h>
#include <pkg.h>
@@ -464,11 +465,19 @@ exec_query(int argc, char **argv)
		
		print_query(pkg, argv[0], multiline);
		pkg_free(pkg);
-
		return (0);
+
		return (EXIT_SUCCESS);
	}

-
	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
-
		return (EX_IOERR);
+
	ret = pkgdb_open(&db, PKGDB_DEFAULT);
+
	if (ret == EPKG_ENODB) {
+
		if (geteuid() == 0)
+
			err(EX_IOERR, "Unable to create local database");
+

+
		if (match == MATCH_ALL)
+
			return (EXIT_SUCCESS);
+

+
		return (EXIT_FAILURE);
+
	}

	if (match == MATCH_ALL) {
		if ((it = pkgdb_query(db, NULL, match)) == NULL)