Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add package removing function.
Vsevolod Stakhov committed 13 years ago
commit f32826da195b54c3772da3229f4a6d265def6e96
parent 3dfa32c
3 files changed +50 -20
modified libpkg/pkg_repo.c
@@ -322,7 +322,8 @@ pkg_create_repo(char *path, bool force, void (progress)(struct pkg *pkg, void *d
		cur_dig->files_pos = files_pos;
		LL_PREPEND(dlist, cur_dig);

-
		retcode = pkgdb_repo_add_package(r->pkg, r->path, sqlite, manifest_digest);
+
		retcode = pkgdb_repo_add_package(r->pkg, r->path, sqlite,
+
				manifest_digest, false);
		if (retcode == EPKG_END) {
			continue;
		}
modified libpkg/pkgdb_repo.c
@@ -414,7 +414,7 @@ pkgdb_repo_close(sqlite3 *sqlite, bool commit)

static int
maybe_delete_conflicting(const char *origin, const char *version,
-
			 const char *pkg_path)
+
			 const char *pkg_path, bool forced)
{
	int ret = EPKG_FATAL;
	const char *oversion;
@@ -422,24 +422,32 @@ maybe_delete_conflicting(const char *origin, const char *version,
	if (run_prepared_statement(VERSION, origin) != SQLITE_ROW)
		return (EPKG_FATAL); /* sqlite error */
	oversion = sqlite3_column_text(STMT(VERSION), 0);
-
	switch(pkg_version_cmp(oversion, version)) {
-
	case -1:
-
		pkg_emit_error("duplicate package origin: replacing older "
-
			       "version %s in repo with package %s for "
-
			       "origin %s", oversion, pkg_path, origin);
+
	if (!forced) {
+
		switch(pkg_version_cmp(oversion, version)) {
+
		case -1:
+
			pkg_emit_error("duplicate package origin: replacing older "
+
					"version %s in repo with package %s for "
+
					"origin %s", oversion, pkg_path, origin);

+
			if (run_prepared_statement(DELETE, origin) != SQLITE_DONE)
+
				return (EPKG_FATAL); /* sqlite error */
+

+
			ret = EPKG_OK;	/* conflict cleared */
+
			break;
+
		case 0:
+
		case 1:
+
			pkg_emit_error("duplicate package origin: package %s is not "
+
					"newer than version %s already in repo for "
+
					"origin %s", pkg_path, oversion, origin);
+
			ret = EPKG_END;	/* keep what is already in the repo */
+
			break;
+
		}
+
	}
+
	else {
		if (run_prepared_statement(DELETE, origin) != SQLITE_DONE)
			return (EPKG_FATAL); /* sqlite error */

-
		ret = EPKG_OK;	/* conflict cleared */
-
		break;
-
	case 0:
-
	case 1:
-
		pkg_emit_error("duplicate package origin: package %s is not "
-
			       "newer than version %s already in repo for "
-
			       "origin %s", pkg_path, oversion, origin);
-
		ret = EPKG_END;	/* keep what is already in the repo */
-
		break;
+
		ret = EPKG_OK;
	}
	return (ret);
}
@@ -459,7 +467,7 @@ pkgdb_repo_cksum_exists(sqlite3 *sqlite, const char *cksum)

int
pkgdb_repo_add_package(struct pkg *pkg, const char *pkg_path,
-
		sqlite3 *sqlite, const char *manifest_digest)
+
		sqlite3 *sqlite, const char *manifest_digest, bool forced)
{
	const char *name, *version, *origin, *comment, *desc;
	const char *arch, *maintainer, *www, *prefix, *sum, *rpath;
@@ -488,7 +496,7 @@ try_again:
			rpath, manifest_digest)) != SQLITE_DONE) {
		if (ret == SQLITE_CONSTRAINT) {
			switch(maybe_delete_conflicting(origin,
-
					version, pkg_path)) {
+
					version, pkg_path, forced)) {
			case EPKG_FATAL: /* sqlite error */
				ERROR_SQLITE(sqlite);
				return (EPKG_FATAL);
@@ -589,6 +597,19 @@ try_again:
	return (EPKG_OK);
}

+
int
+
pkgdb_repo_remove_package(struct pkg *pkg)
+
{
+
	const char *origin;
+

+
	pkg_get(pkg, PKG_ORIGIN, &origin);
+

+
	if (run_prepared_statement(DELETE, origin) != SQLITE_DONE)
+
		return (EPKG_FATAL); /* sqlite error */
+

+
	return (EPKG_OK);
+
}
+

/* We want to replace some arbitrary number of instances of the placeholder
   %Q in the SQL with the name of the database. */
static int
modified libpkg/private/pkgdb.h
@@ -100,17 +100,25 @@ int pkgdb_repo_cksum_exists(sqlite3 *sqlite, const char *cksum);
 * @param pkg_path path triggered package addition
 * @param sqlite sqlite pointer
 * @param manifest_digest sha256 checksum of the manifest of the package
+
 * @param forced force adding of package even if it is outdated
 * @return EPKG_OK if package added, EPKG_END if package already exists and is newer than
 * inserted one, EPKG_FATAL if error occurred
 */
int pkgdb_repo_add_package(struct pkg *pkg, const char *pkg_path,
-
		sqlite3 *sqlite, const char *manifest_digest);
+
		sqlite3 *sqlite, const char *manifest_digest, bool forced);
+

+
/**
+
 * Remove specified pkg from repo
+
 * @param pkg package to remove
+
 * @return EPKG_OK if succeeded
+
 */
+
int pkgdb_repo_remove_package(struct pkg *pkg);

/**
 * Upgrade repo db version if required
 * @param db package database object
 * @param database name of database
-
 * @return
+
 * @return EPKG_OK if succeeded
 */
int pkgdb_repo_check_version(struct pkgdb *db, const char *database);