Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
register in database : architecture with a fallback on system one osversion (if not released __FreeBSD_version is appended to the release name) www with a fallback on determing it in description
Baptiste Daroussin committed 15 years ago
commit 4ba82350a6d615420d14ce7d451fcd85c55eaae7
parent 1b43fed910c46f1945e4bc0414ccbbf1519e0508
2 files changed +58 -7
modified libpkg/pkgdb.c
@@ -142,7 +142,7 @@ pkgdb_init(sqlite3 *sdb)
		"package_id TEXT REFERENCES packages(origin) ON DELETE CASCADE, "
		"option TEXT,"
		"value TEXT,"
-
		"PRIMARY KEY (package_id,name)"
+
		"PRIMARY KEY (package_id,option)"
	");"
	"CREATE INDEX options_package ON options (package_id);"
	"CREATE TABLE deps ("
@@ -547,7 +547,7 @@ pkgdb_query(struct pkgdb *db, const char *pattern, match_t match)
	}

	snprintf(sql, sizeof(sql),
-
			"SELECT origin, name, version, comment, desc, mtree, message, arch, osversion, maintainer, www, FROM packages%s;", comp);
+
			"SELECT origin, name, version, comment, desc, mtree, message, arch, osversion, maintainer, www FROM packages%s;", comp);

	sqlite3_prepare(db->sqlite, sql, -1, &stmt, NULL);

@@ -563,7 +563,7 @@ pkgdb_query_which(struct pkgdb *db, const char *path)
	sqlite3_stmt *stmt;

	sqlite3_prepare(db->sqlite,
-
					"SELECT origin, name, version, comment, desc, mtree, message, arch, osversion, maintainer, www,  FROM packages, files "
+
					"SELECT origin, name, version, comment, desc, mtree, message, arch, osversion, maintainer, www  FROM packages, files "
					"WHERE origin = files.package_id "
					"AND files.path = ?1;", -1, &stmt, NULL);
	sqlite3_bind_text(stmt, 1, path, -1, SQLITE_TRANSIENT);
@@ -709,8 +709,8 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)

	sqlite3_exec(db->sqlite, "BEGIN TRANSACTION;", NULL, NULL, NULL);

-
	sqlite3_prepare(db->sqlite, "INSERT OR REPLACE INTO packages (origin, name, version, comment, desc, mtree, message) "
-
			"VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)",
+
	sqlite3_prepare(db->sqlite, "INSERT OR REPLACE INTO packages (origin, name, version, comment, desc, mtree, message, arch, osversion, maintainer, www) "
+
			"VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)",
			-1, &stmt_pkg, NULL);

	sqlite3_prepare(db->sqlite, "INSERT INTO deps (origin, name, version, package_id)"
@@ -744,6 +744,10 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg)
	sqlite3_bind_text(stmt_pkg, 5, pkg_get(pkg, PKG_DESC), -1, SQLITE_STATIC);
	sqlite3_bind_text(stmt_pkg, 6, pkg_get(pkg, PKG_MTREE), -1, SQLITE_STATIC);
	sqlite3_bind_text(stmt_pkg, 7, pkg_get(pkg, PKG_MESSAGE), -1, SQLITE_STATIC);
+
	sqlite3_bind_text(stmt_pkg, 8, pkg_get(pkg, PKG_ARCH), -1, SQLITE_STATIC);
+
	sqlite3_bind_text(stmt_pkg, 9, pkg_get(pkg, PKG_OSVERSION), -1, SQLITE_STATIC);
+
	sqlite3_bind_text(stmt_pkg, 10, pkg_get(pkg, PKG_MAINTAINER), -1, SQLITE_STATIC);
+
	sqlite3_bind_text(stmt_pkg, 11, pkg_get(pkg, PKG_WWW), -1, SQLITE_STATIC);

	sqlite3_step(stmt_pkg);

modified pkg/register.c
@@ -6,6 +6,8 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
+
#include <sys/utsname.h>
+
#include <regex.h>

#include "register.h"

@@ -21,11 +23,19 @@ exec_register(int argc, char **argv)
{
	struct pkg *pkg;
	struct pkgdb *db;
+
	struct utsname u;
+

+
	regex_t preg;
+
	regmatch_t *pmatch = NULL;

	char ch;
	char *plist = NULL;
	char *prefix = NULL;
	char *v = NULL;
+
	char *arch = NULL;
+
	char *www = NULL;
+
	const char *desc = NULL;
+
	size_t size;

	int ret = 0;

@@ -73,13 +83,13 @@ exec_register(int argc, char **argv)
				ret += ports_parse_scripts(pkg, optarg);
				break;
			case 'a':
-
				pkg_set(pkg, PKG_ARCH, optarg);
+
				arch = strdup(optarg);
				break;
			case 'r': /* responsible */
				pkg_set(pkg, PKG_MAINTAINER, optarg);
				break;
			case 'w':
-
				pkg_set(pkg, PKG_WWW, optarg);
+
				www = strdup(optarg);
				break;
			case 'O':
				ret += ports_parse_options(pkg, optarg);
@@ -91,6 +101,43 @@ exec_register(int argc, char **argv)
		}
	}

+
	uname(&u);
+
	if (arch == NULL) {
+
		pkg_set(pkg, PKG_ARCH, u.machine);
+
	} else {
+
		pkg_set(pkg, PKG_ARCH, arch);
+
		free(arch);
+
	}
+

+
	/* is www is not given then try to determine it from description */
+
	if (www == NULL) {
+
		desc = pkg_get(pkg, PKG_DESC);
+
		regcomp(&preg, "^WWW:[:space:]*(.*)$", REG_EXTENDED|REG_ICASE|REG_NEWLINE);
+
		pmatch = malloc(sizeof(regmatch_t) * (preg.re_nsub + 1));
+
		if (regexec(&preg, desc, preg.re_nsub + 1, pmatch, 0) == 0) {
+
			size = pmatch[1].rm_eo - pmatch[1].rm_so;
+
			www = malloc(sizeof(char) * size + 1);
+
			strncpy (www, &desc[pmatch[1].rm_so], size);
+
			www[size] = '\0';
+
			pkg_set(pkg, PKG_WWW, www);
+
			free(www);
+

+
		}
+
	} else {
+
		pkg_set(pkg, PKG_WWW, www);
+
		free(www);
+
	}
+

+

+
	if (strstr(u.release, "RELEASE") == NULL) {
+
		v = malloc(strlen(u.release) + 10); /* 10 should be enough */
+
		snprintf(v, strlen(u.release) + 10, "%s-%d", u.release, __FreeBSD_version);
+
		pkg_set(pkg, PKG_OSVERSION, v);
+
		free(v);
+
	} else {
+
		pkg_set(pkg, PKG_OSVERSION, u.release);
+
	}
+
	pkg_set(pkg, PKG_ARCH, optarg);
	/* TODO: missing osversion get it from uname*/

	if (ret < 0) {