Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add new case insensitive match capability.
Matthew Seaman committed 13 years ago
commit ba3f5eec95fddb1b4f8091f99d0cc837cc41fc58
parent 55ba492c0a2570065743583031c3e1cae2319b2d
5 files changed +31 -28
modified libpkg/pkg.c
@@ -1144,13 +1144,19 @@ pkg_recompute(struct pkgdb *db, struct pkg *pkg)
}

int
-
pkg_is_installed(struct pkgdb *db, const char *origin)
+
pkg_is_installed(struct pkgdb *db, const char *origin, bool case_insensitive)
{
	struct pkg *pkg = NULL;
	struct pkgdb_it *it = NULL;
	int ret = EPKG_FATAL;
+
	match_t	match_type;

-
	if ((it = pkgdb_query(db, origin, MATCH_EXACT)) == NULL)
+
	if (case_insensitive)
+
		match_type = MATCH_EXACT;
+
	else
+
		match_type = MATCH_CASE_INSENSITIVE;
+

+
	if ((it = pkgdb_query(db, origin, match_type)) == NULL)
		return (EPKG_FATAL);

	ret = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC);
modified libpkg/pkg.h.in
@@ -129,6 +129,11 @@ typedef enum {
	 */
	MATCH_EXACT,
	/**
+
	 * The argument is an exact pattern except that matches
+
	 * will be made case insensitively
+
	 */
+
	MATCH_CASE_INSENSITIVE,
+
	/**
	 * The argument is a globbing expression.
	 */
	MATCH_GLOB,
@@ -786,10 +791,12 @@ const char *pkg_shlib_name(struct pkg_shlib const * const);
/**
 * @param db A pointer to a struct pkgdb object
 * @param origin Package origin
+
 * @param case_insensitive Match the origin name case insensitively
 * @return EPKG_OK if the package is installed,
 * and != EPKG_OK if the package is not installed or an error occurred
 */
-
int pkg_is_installed(struct pkgdb *db, const char *origin);
+
int pkg_is_installed(struct pkgdb *db, const char *origin,
+
		     bool case_insensitive);

/**
 * Create a repository database.
modified libpkg/pkg_add.c
@@ -42,23 +42,6 @@
#include "private/pkg.h"

static int
-
dep_installed(struct pkg_dep *dep, struct pkgdb *db) {
-
	struct pkg	*p = NULL;
-
	struct pkgdb_it	*it;
-
	int		 ret = EPKG_FATAL;
-

-
	it = pkgdb_query(db, pkg_dep_origin(dep), MATCH_EXACT);
-

-
	if (pkgdb_it_next(it, &p, PKG_LOAD_BASIC) == EPKG_OK)
-
		ret = EPKG_OK;
-

-
	pkgdb_it_free(it);
-
	pkg_free(p);
-

-
	return (ret);
-
}
-

-
static int
do_extract(struct archive *a, struct archive_entry *ae)
{
	int	retcode = EPKG_OK;
@@ -183,12 +166,7 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags)
	 * Check if the package is already installed
	 */

-
	ret = EPKG_FATAL; /* assume package is not installed */
-
	if ((it = pkgdb_query(db, origin, MATCH_EXACT)) != NULL) {
-
		ret = pkgdb_it_next(it, &pkg_inst, PKG_LOAD_BASIC);
-
		pkgdb_it_free(it);
-
	}
-

+
	ret = pkg_is_installed(db, origin, false);
	if (ret == EPKG_OK) {
		pkg_emit_already_installed(pkg_inst);
		pkg_free(pkg_inst);
@@ -211,7 +189,7 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags)
	}

	while (pkg_deps(pkg, &dep) == EPKG_OK) {
-
		if (dep_installed(dep, db) != EPKG_OK) {
+
		if (pkg_is_installed(db, pkg_dep_origin(dep), false) != EPKG_OK) {
			const char *dep_name = pkg_dep_name(dep);
			const char *dep_ver = pkg_dep_version(dep);

modified libpkg/pkgdb.c
@@ -1280,6 +1280,14 @@ pkgdb_get_pattern_query(const char *pattern, match_t match)
		else
			comp = " WHERE origin = ?1";
		break;
+
	case MATCH_CASE_INSENSITIVE:
+
		if (checkorigin == NULL)
+
			comp = " WHERE name = ?1 COLLATE NOCASE"
+
				"OR name || \"-\" || version = ?1"
+
				"COLLATE NOCASE";
+
		else
+
			comp = " WHERE origin = ?1 COLLATE NOCASE";
+
		break;
	case MATCH_GLOB:
		if (checkorigin == NULL)
			comp = " WHERE name GLOB ?1 "
@@ -1314,6 +1322,9 @@ pkgdb_get_match_how(match_t match)
	case MATCH_EXACT:
		how = "%s = ?1";
		break;
+
	case MATCH_CASE_INSENSITIVE:
+
		how = "%s = ?1 COLLATE NOCASE";
+
		break;
	case MATCH_GLOB:
		how = "%s GLOB ?1";
		break;
modified pkg/check.c
@@ -71,7 +71,8 @@ check_deps(struct pkgdb *db, struct pkg *p, struct deps_head *dh)

	while (pkg_deps(p, &dep) == EPKG_OK) {
		/* do we have a missing dependency? */
-
		if (pkg_is_installed(db, pkg_dep_origin(dep)) != EPKG_OK) {
+
		if (pkg_is_installed(db, pkg_dep_origin(dep), false)
+
		    != EPKG_OK) {
			printf("%s has a missing dependency: %s\n", origin,
			       pkg_dep_origin(dep)),
			add_missing_dep(dep, dh, &nbpkgs);