Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Cleanup and use pkg_config() instead of pkgdb_get_dir().
jlaffaye committed 15 years ago
commit 0a75901b8a769352f7cb5c52ff5ac4d116ac357c
parent aaad1ab
5 files changed +23 -41
modified libpkg/pkg.h
@@ -475,11 +475,6 @@ int pkgdb_loadmtree(struct pkgdb *db, struct pkg *pkg);
int pkgdb_compact(struct pkgdb *db);

/**
-
 * Return the path where the database live.
-
 */
-
const char *pkgdb_get_dir(void);
-

-
/**
 * Install and register a new package.
 * @param path The path to the package archive file on the local disk
 * @return An error code.
modified libpkg/pkg_config.c
@@ -17,6 +17,7 @@ struct _config {
	const char *val;
} c[] = {
	{ "PACKAGESITE", NULL, NULL},
+
	{ "PKG_DBDIR", "/var/db/pkg", NULL},
	{ NULL, NULL, NULL}
};

modified libpkg/pkg_delete.c
@@ -15,7 +15,6 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, int force)
	struct pkg_exec **execs;
	struct pkg_script **scripts;
	char sha256[65];
-
	const char *prefix;
	struct sbuf *script_cmd;
	int ret, i;

@@ -43,7 +42,6 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, int force)
	files = pkg_files(pkg);
	scripts = pkg_scripts(pkg);
	execs = pkg_execs(pkg);
-
	prefix = pkg_get(pkg, PKG_PREFIX);

	if (rdeps[0] != NULL && force == 0)
		return (pkg_error_set(EPKG_REQUIRED, "this package is required by "
modified libpkg/pkgdb.c
@@ -18,27 +18,16 @@
#include "pkgdb.h"
#include "pkg_util.h"

-
#define PKG_DBDIR "/var/db/pkg"
-

static struct pkgdb_it * pkgdb_it_new(struct pkgdb *, sqlite3_stmt *);
static void pkgdb_regex(sqlite3_context *, int, sqlite3_value **, int);
static void pkgdb_regex_basic(sqlite3_context *, int, sqlite3_value **);
-
static void pkgdb_pkglt(sqlite3_context *, int, sqlite3_value **);
-
static void pkgdb_pkggt(sqlite3_context *, int, sqlite3_value **);
static void pkgdb_regex_extended(sqlite3_context *, int, sqlite3_value **);
static void pkgdb_regex_delete(void *);
+
static void pkgdb_pkglt(sqlite3_context *, int, sqlite3_value **);
+
static void pkgdb_pkggt(sqlite3_context *, int, sqlite3_value **);
static int get_pragma(sqlite3 *, const char *, int64_t *);

static void
-
pkgdb_regex_delete(void *p)
-
{
-
	regex_t *re = (regex_t *)p;
-

-
	regfree(re);
-
	free(re);
-
}
-

-
static void
pkgdb_regex(sqlite3_context *ctx, int argc, sqlite3_value **argv, int reg_type)
{
	const unsigned char *regex = NULL;
@@ -75,6 +64,21 @@ pkgdb_regex_basic(sqlite3_context *ctx, int argc, sqlite3_value **argv)
}

static void
+
pkgdb_regex_extended(sqlite3_context *ctx, int argc, sqlite3_value **argv)
+
{
+
	pkgdb_regex(ctx, argc, argv, REG_EXTENDED);
+
}
+

+
static void
+
pkgdb_regex_delete(void *p)
+
{
+
	regex_t *re = (regex_t *)p;
+

+
	regfree(re);
+
	free(re);
+
}
+

+
static void
pkgdb_pkgcmp(sqlite3_context *ctx, int argc, sqlite3_value **argv, int sign)
{
	const unsigned char *version1 = NULL;
@@ -100,23 +104,6 @@ pkgdb_pkggt(sqlite3_context *ctx, int argc, sqlite3_value **argv)
	pkgdb_pkgcmp(ctx, argc, argv, PKG_GT);
}

-
static void
-
pkgdb_regex_extended(sqlite3_context *ctx, int argc, sqlite3_value **argv)
-
{
-
	pkgdb_regex(ctx, argc, argv, REG_EXTENDED);
-
}
-

-
const char *
-
pkgdb_get_dir(void)
-
{
-
	const char *pkg_dbdir;
-

-
	if ((pkg_dbdir = getenv("PKG_DBDIR")) == NULL)
-
		pkg_dbdir = PKG_DBDIR;
-

-
	return pkg_dbdir;
-
}
-

/*
 * in the database : 
 * scripts.type can be:
@@ -235,7 +222,8 @@ pkgdb_open(struct pkgdb **db, pkgdb_t remote)
	char remotepath[MAXPATHLEN];
	char sql[BUFSIZ];

-
	snprintf(localpath, sizeof(localpath), "%s/local.sqlite", pkgdb_get_dir());
+
	snprintf(localpath, sizeof(localpath), "%s/local.sqlite",
+
			 pkg_config("PKG_DBDIR"));

	if ((*db = calloc(1, sizeof(struct pkgdb))) == NULL)
		return (pkg_error_set(EPKG_FATAL, "calloc(): %s", strerror(errno)));
@@ -247,7 +235,8 @@ pkgdb_open(struct pkgdb **db, pkgdb_t remote)
							  strerror(errno)));

	if (remote == PKGDB_REMOTE) {
-
		snprintf(remotepath, sizeof(localpath), "%s/repo.sqlite", pkgdb_get_dir());
+
		snprintf(remotepath, sizeof(localpath), "%s/repo.sqlite",
+
				 pkg_config("PKG_DBDIR"));
		if ((retcode = stat(remotepath, &st)) == -1 && errno != ENOENT)
			return (pkg_error_set(EPKG_FATAL, "can not stat %s: %s", remotepath,
						strerror(errno)));
modified pkg/upgrade.c
@@ -39,7 +39,7 @@ exec_upgrade(int argc, char **argv)
	}

	if (geteuid() != 0) {
-
		warnx("updating the remote database can only be done as root");
+
		warnx("upgrading can only be done as root");
		return (EX_NOPERM);
	}

@@ -48,7 +48,6 @@ exec_upgrade(int argc, char **argv)
		return (1);
	}

-

	if ((it = pkgdb_query_upgrades(db)) == NULL) {
		pkg_error_warn("can not query database");
		goto cleanup;