Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add pkg_delannotation()
Matthew Seaman committed 13 years ago
commit 93b70c76926d99b1780e3fbfabd7def7aa1bfcea
parent 6752c6e
5 files changed +37 -7
modified libpkg/pkg.c
@@ -909,11 +909,12 @@ pkg_addannotation(struct pkg *pkg, const char *key, const char *value)

	assert(pkg != NULL);
	assert(key != NULL && key[0] != '\0');
-
	assert(value != NULL && value[0] != '\0');
+
	assert(value != NULL);
+

+
	/* Keys are unique per-package */

-
	/* The combination of key+value should be unique */
	HASH_FIND_STR(pkg->annotations, __DECONST(char *, key), an);
-
	if (an != NULL && strcmp(value, pkg_annotation_value(an)) == 0) {
+
	if (an != NULL) {
		pkg_emit_error("duplicate annotation listing: %s -- %s,"
			       " ignoring", key, value);
		return (EPKG_OK);
@@ -932,6 +933,27 @@ pkg_addannotation(struct pkg *pkg, const char *key, const char *value)
}

int
+
pkg_delannotation(struct pkg *pkg, const char *key)
+
{
+
	struct pkg_note *an = NULL;
+

+
	assert(pkg != NULL);
+
	assert(key != NULL && key[0] != '\0');
+

+
	HASH_FIND_STR(pkg->annotations, __DECONST(char *, key), an);
+
	if (an != NULL) {
+
		HASH_DEL(pkg->annotations,
+
		    __DECONST(char *, pkg_annotation_key(an)));
+
		pkg_annotation_free(an);
+
		return (EPKG_OK);
+
	} else {
+
		pkg_emit_error("deleting key %s -- no annotation found"
+
			       " with matching key", key);
+
		return (EPKG_WARN);
+
	}
+
}
+

+
int
pkg_list_count(struct pkg *pkg, pkg_list list)
{
	switch (list) {
modified libpkg/pkg.h.in
@@ -768,6 +768,12 @@ int pkg_addshlib_provided(struct pkg *pkg, const char *name);
int pkg_addannotation(struct pkg *pkg, const char *key, const char *value);

/**
+
 * Delete annotation identified by the key
+
 * @return An error code
+
 */
+
int pkg_delannotation(struct pkg *pkg, const char *key);
+

+
/**
 * Parse a manifest and set the attributes of pkg accordingly.
 * @param buf An NULL-terminated buffer containing the manifest data.
 * @return An error code.
modified libpkg/pkgdb.c
@@ -648,7 +648,7 @@ pkgdb_init(sqlite3 *sdb)
                      " ON DELETE CASCADE ON UPDATE RESTRICT,"
		"value_id INTEGER NOT NULL REFERENCES annotation(annotation_id)"
		      " ON DELETE CASCADE ON UPDATE RESTRICT,"
-
		"UNIQUE (package_id, key_id, value_id)"
+
		"UNIQUE (package_id, key_id)"
	");"

	/* Mark the end of the array */
modified libpkg/private/db_upgrades.h
@@ -317,7 +317,8 @@ static struct db_upgrades {
                "key_id INTEGER NOT NULL REFERENCES annotation(annotation_id)"
                      " ON DELETE CASCADE ON UPDATE RESTRICT,"
		"value_id INTEGER NOT NULL REFERENCES annotation(annotation_id)"
-
		      " ON DELETE CASCADE ON UPDATE RESTRICT"
+
	 	      " ON DELETE CASCADE ON UPDATE RESTRICT,"
+
	        "UNIQUE(package_id, key_id)"
	");"
	"CREATE INDEX pkg_annotation_package_id ON pkg_annotation(package_id);"
	"INSERT INTO annotation (annotation_id, annotation)"
modified libpkg/private/repodb.h
@@ -126,7 +126,7 @@ static const char initsql[] = ""
	    " ON DELETE CASCADE ON UPDATE RESTRICT,"
	    "value_id INTEGER NOT NULL REFERENCES annotation(annotation_id)"
	    " ON DELETE CASCADE ON UPDATE RESTRICT,"
-
	    "UNIQUE (package_id, key_id, value_id)"
+
	    "UNIQUE (package_id, key_id)"
	");"
	"PRAGMA user_version=%d;"
	;
@@ -197,7 +197,8 @@ static const struct repo_changes repo_upgrades[] = {
	        "key_id INTEGER NOT NULL REFERENCES annotation(annotation_id)"
	        " ON DELETE CASCADE ON UPDATE RESTRICT,"
	        "value_id INTEGER NOT NULL REFERENCES annotation(annotation_id)"
-
	        " ON DELETE CASCADE ON UPDATE RESTRICT"
+
	        " ON DELETE CASCADE ON UPDATE RESTRICT,"
+
	        "UNIQUE (package_id, key_id)"
	 ");"
	 "INSERT INTO %Q.annotation (annotation_id, annotation)"
	        " SELECT abstract_id, abstract FROM %Q.abstract;"