Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Remove old integritycheck.
Vsevolod Stakhov committed 11 years ago
commit fdf118182994995fab9561c7eee2a247c6cc9e04
parent 3377d97
4 files changed +23 -231
modified libpkg/pkg_jobs.c
@@ -2165,6 +2165,8 @@ pkg_jobs_check_conflicts(struct pkg_jobs *j)
	pkg_debug(1, "check integrity for %d items added", added);

	pkg_emit_integritycheck_finished(j->conflicts_registered);
+
	if (j->conflicts_registered > 0)
+
		ret = EPKG_CONFLICT;

	return (ret);
}
modified libpkg/pkg_jobs_conflicts.c
@@ -194,16 +194,19 @@ pkg_conflicts_item_cmp(struct pkg_jobs_conflict_item *a,
 * Checks whether we need to add a conflict between two packages
 */
static bool
-
pkg_conflicts_need_conflict(struct pkg *p1, struct pkg *p2)
+
pkg_conflicts_need_conflict(struct pkg_jobs *j, struct pkg *p1, struct pkg *p2)
{
	struct pkg_file *fcur, *ftmp, *ff;
-
	struct pkg_dir *dcur, *dtmp, *df;
+
	struct pkg_dir *df;
	const char *uid1, *uid2;
	struct pkg_conflict *c;

	pkg_get(p1, PKG_UNIQUEID, &uid1);
	pkg_get(p2, PKG_UNIQUEID, &uid2);

+
	assert(pkgdb_ensure_loaded(j->db, p1, PKG_LOAD_FILES|PKG_LOAD_DIRS) == EPKG_OK);
+
	assert(pkgdb_ensure_loaded(j->db, p2, PKG_LOAD_FILES|PKG_LOAD_DIRS) == EPKG_OK);
+

	/*
	 * Check if we already have this conflict registered
	 */
@@ -222,14 +225,7 @@ pkg_conflicts_need_conflict(struct pkg *p1, struct pkg *p2)
		if (df != NULL)
			return (true);
	}
-
	HASH_ITER(hh, p1->dirs, dcur, dtmp) {
-
		HASH_FIND_STR(p2->files, dcur->path, ff);
-
		if (ff != NULL)
-
			return (true);
-
		HASH_FIND_STR(p2->dirs, dcur->path, df);
-
		if (df != NULL)
-
			return (true);
-
	}
+
	/* XXX pkg dirs are terribly broken */

	/* No common paths are found in p1 and p2 */
	return (false);
@@ -240,6 +236,7 @@ pkg_conflicts_need_conflict(struct pkg *p1, struct pkg *p2)
 */
static void
pkg_conflicts_register_unsafe(struct pkg *p1, struct pkg *p2,
+
	const char *path,
	enum pkg_conflict_type type)
{
	const char *uid1, *uid2;
@@ -257,7 +254,8 @@ pkg_conflicts_register_unsafe(struct pkg *p1, struct pkg *p2,
		sbuf_size(c1->uniqueid), c1);
	HASH_ADD_KEYPTR(hh, p2->conflicts, pkg_conflict_uniqueid(c2),
		sbuf_size(c2->uniqueid), c2);
-
	pkg_debug(2, "registering conflict between %s and %s", uid1, uid2);
+
	pkg_debug(2, "registering conflict between %s and %s on path %s",
+
		uid1, uid2, path);
}

/*
@@ -265,7 +263,7 @@ pkg_conflicts_register_unsafe(struct pkg *p1, struct pkg *p2,
 */
static bool
pkg_conflicts_register_chain(struct pkg_jobs *j, struct pkg_job_universe_item *u1,
-
	struct pkg_job_universe_item *u2)
+
	struct pkg_job_universe_item *u2, const char *path)
{
	struct pkg_job_universe_item *cur1, *cur2;
	const char *uid1, *uid2;
@@ -287,8 +285,8 @@ pkg_conflicts_register_chain(struct pkg_jobs *j, struct pkg_job_universe_item *u
			}
			else if (p1->type == PKG_INSTALLED || p2->type == PKG_INSTALLED) {
				/* local <-> remote conflict */
-
				if (pkg_conflicts_need_conflict(p1, p2)) {
-
					pkg_conflicts_register_unsafe(p1, p2,
+
				if (pkg_conflicts_need_conflict(j, p1, p2)) {
+
					pkg_conflicts_register_unsafe(p1, p2, path,
						PKG_CONFLICT_REMOTE_LOCAL);
					j->conflicts_registered ++;
					ret = true;
@@ -296,8 +294,8 @@ pkg_conflicts_register_chain(struct pkg_jobs *j, struct pkg_job_universe_item *u
			}
			else {
				/* two remote packages */
-
				if (pkg_conflicts_need_conflict(p1, p2)) {
-
					pkg_conflicts_register_unsafe(p1, p2,
+
				if (pkg_conflicts_need_conflict(j, p1, p2)) {
+
					pkg_conflicts_register_unsafe(p1, p2, path,
						PKG_CONFLICT_REMOTE_REMOTE);
					j->conflicts_registered ++;
					ret = true;
@@ -408,7 +406,7 @@ pkg_conflicts_check_all_paths(struct pkg_jobs *j, const char *path,

		/* Here we can have either collision or a real conflict */
		HASH_FIND_STR(it->pkg->conflicts, uid2, c);
-
		if (c != NULL || !pkg_conflicts_register_chain(j, it, cit->item)) {
+
		if (c != NULL || !pkg_conflicts_register_chain(j, it, cit->item, path)) {
			/*
			 * Collision found, change the key following the
			 * Cuckoo principle
@@ -430,7 +428,6 @@ pkg_conflicts_check_chain_conflict(struct pkg_job_universe_item *it,
	struct pkg_job_universe_item *local, struct pkg_jobs *j)
{
	struct pkg_file *fcur, *ftmp, *ff;
-
	struct pkg_dir *dcur, *dtmp, *df;
	const char *uid;
	struct pkg *p;
	struct pkg_job_universe_item *cun;
@@ -455,9 +452,12 @@ pkg_conflicts_check_chain_conflict(struct pkg_job_universe_item *it,
		if (p != NULL) {
			pkg_jobs_universe_process_item(j->universe, p, &cun);
			assert(cun != NULL);
-
			pkg_conflicts_register_chain(j, it, cun);
+
			pkg_conflicts_register_chain(j, it, cun, fcur->path);
		}
	}
+
	/* XXX: dirs are currently broken terribly */
+
#if 0
+
	struct pkg_dir *dcur, *dtmp, *df;
	HASH_ITER(hh, it->pkg->dirs, dcur, dtmp) {
		memset(&k, 0, sizeof(k));
		cun = pkg_conflicts_check_all_paths(j, dcur->path, it, &k);
@@ -472,9 +472,10 @@ pkg_conflicts_check_chain_conflict(struct pkg_job_universe_item *it,
		if (p != NULL) {
			pkg_jobs_universe_process_item(j->universe, p, &cun);
			assert(cun != NULL);
-
			pkg_conflicts_register_chain(j, it, cun);
+
			pkg_conflicts_register_chain(j, it, cun, dcur->path);
		}
	}
+
#endif
}

int
modified libpkg/pkgdb.c
@@ -2359,210 +2359,6 @@ pkgdb_compact(struct pkgdb *db)
	return (sql_exec(db->sqlite, "VACUUM;"));
}

-
int
-
pkgdb_integrity_append(struct pkgdb *db, struct pkg *p,
-
		conflict_func_cb cb, void *cbdata)
-
{
-
	int		 ret = EPKG_OK;
-
	sqlite3_stmt	*stmt = NULL;
-
	sqlite3_stmt	*stmt_conflicts = NULL;
-
	struct pkg_file	*file = NULL;
-
	const char *puid;
-

-
	const char	 sql[] = ""
-
		"INSERT INTO integritycheck (uid, path)"
-
		"values (?1, ?2);";
-
	const char	 sql_conflicts[] = ""
-
		"SELECT uid FROM integritycheck where path=?1;";
-

-
	assert(db != NULL && p != NULL);
-

-
	sql_exec(db->sqlite, "CREATE TEMP TABLE IF NOT EXISTS integritycheck ("
-
			"uid TEXT, "
-
			"path TEXT UNIQUE);"
-
		);
-

-
	pkg_debug(4, "Pkgdb: running '%s'", sql);
-
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL)
-
	    != SQLITE_OK) {
-
		ERROR_SQLITE(db->sqlite, sql);
-
		return (EPKG_FATAL);
-
	}
-

-
	pkg_get(p, PKG_UNIQUEID, &puid);
-

-
	pkg_debug(4, "Pkgdb: test conflicts for %s", puid);
-
	while (pkg_files(p, &file) == EPKG_OK) {
-
		const char	*uid;
-
		const char	*pkg_path = pkg_file_path(file);
-
		struct pkg_event_conflict *conflicts_list = NULL, *cur;
-

-
		pkg_get(p, PKG_UNIQUEID, &uid);
-
		sqlite3_bind_text(stmt, 1, uid, -1, SQLITE_STATIC);
-
		sqlite3_bind_text(stmt, 2, pkg_path, -1, SQLITE_STATIC);
-

-
		if (sqlite3_step(stmt) != SQLITE_DONE) {
-

-
			pkg_debug(4, "Pkgdb: running '%s'", sql_conflicts);
-
			if (sqlite3_prepare_v2(db->sqlite, sql_conflicts,
-
			    -1, &stmt_conflicts, NULL) != SQLITE_OK) {
-
				ERROR_SQLITE(db->sqlite, sql_conflicts);
-
				sqlite3_finalize(stmt);
-
				return (EPKG_FATAL);
-
			}
-

-
			sqlite3_bind_text(stmt_conflicts, 1, pkg_path,
-
			    -1, SQLITE_STATIC);
-
			cur = conflicts_list;
-
			while (sqlite3_step(stmt_conflicts) != SQLITE_DONE) {
-

-
				cur = calloc(1, sizeof (struct pkg_event_conflict));
-
				cur->uid = strdup(sqlite3_column_text(stmt_conflicts, 0));
-
				pkg_debug(3, "found conflict between %s and %s on path %s",
-
						puid, cur->uid, pkg_path);
-
				LL_PREPEND(conflicts_list, cur);
-

-
				if (cb != NULL)
-
					cb (puid, cur->uid, cbdata);
-
			}
-
			sqlite3_finalize(stmt_conflicts);
-
			pkg_emit_integritycheck_conflict(uid, pkg_path, conflicts_list);
-

-
			cur = conflicts_list;
-
			while (cur) {
-
				free(cur->uid);
-
				cur = cur->next;
-
				free(conflicts_list);
-
				conflicts_list = cur;
-
			}
-
			ret = EPKG_CONFLICT;
-
		}
-
		sqlite3_reset(stmt);
-
	}
-
	sqlite3_finalize(stmt);
-

-
	return (ret);
-
}
-

-
int
-
pkgdb_integrity_check(struct pkgdb *db, conflict_func_cb cb, void *cbdata)
-
{
-
	int		 ret, retcode = EPKG_OK;
-
	sqlite3_stmt	*stmt;
-
	sqlite3_stmt	*stmt_conflicts;
-
	struct sbuf	*conflictmsg = NULL;
-
	struct sbuf	*uniqueid;
-

-
	assert (db != NULL);
-

-
	const char	 sql_local_conflict[] = ""
-
		"SELECT p.name, p.version, p.origin, p.name || '~' || p.origin as uniqueid FROM packages AS p, files AS f "
-
		"WHERE p.id = f.package_id AND f.path = ?1;";
-

-
	const char	 sql_conflicts[] = ""
-
		"SELECT uid FROM integritycheck WHERE path = ?1;";
-

-
	const char sql_integrity_prepare[] = ""
-
		"SELECT f.path FROM files as f, integritycheck as i "
-
		"LEFT JOIN packages as p ON "
-
		"p.id = f.package_id "
-
		"WHERE f.path = i.path AND "
-
		"p.name || '~' || p.origin != i.uid "
-
		"GROUP BY f.path";
-

-
	/*
-
	 * Select paths that are both in integritycheck and local table but their
-
	 * UIDs are different
-
	 */
-
	pkg_debug(4, "Pkgdb: running '%s'", sql_integrity_prepare);
-
	if (sqlite3_prepare_v2(db->sqlite,
-
		sql_integrity_prepare,
-
		-1, &stmt, NULL) != SQLITE_OK) {
-
		ERROR_SQLITE(db->sqlite, sql_integrity_prepare);
-
		return (EPKG_FATAL);
-
	}
-

-
	conflictmsg = sbuf_new_auto();
-
	uniqueid = sbuf_new_auto();
-

-
	while (sqlite3_step(stmt) != SQLITE_DONE) {
-
		const char *conflict_path;
-

-
		sbuf_clear(conflictmsg);
-
		sbuf_clear(uniqueid);
-

-
		/*
-
		 * Conflict found on path, so find the corresponding local
-
		 * package
-
		 */
-
		pkg_debug(4, "Pkgdb: running '%s'", sql_local_conflict);
-
		ret = sqlite3_prepare_v2(db->sqlite, sql_local_conflict, -1,
-
		    &stmt_conflicts, NULL);
-
		if (ret != SQLITE_OK) {
-
			ERROR_SQLITE(db->sqlite, sql_local_conflict);
-
			sqlite3_finalize(stmt);
-
			sbuf_delete(uniqueid);
-
			sbuf_delete(conflictmsg);
-
			return (EPKG_FATAL);
-
		}
-

-
		conflict_path = sqlite3_column_text(stmt, 0);
-
		sqlite3_bind_text(stmt_conflicts, 1,
-
			conflict_path, -1, SQLITE_STATIC);
-

-
		sqlite3_step(stmt_conflicts);
-

-
		sbuf_printf(conflictmsg,
-
		    "WARNING: locally installed %s-%s conflicts on %s with:\n",
-
		    sqlite3_column_text(stmt_conflicts, 0),
-
		    sqlite3_column_text(stmt_conflicts, 1),
-
		    sqlite3_column_text(stmt, 0));
-
		sbuf_cpy(uniqueid, sqlite3_column_text(stmt_conflicts, 3));
-
		sqlite3_finalize(stmt_conflicts);
-

-
		/*
-
		 * Now match local and remote conflicting packages
-
		 */
-
		pkg_debug(4, "Pkgdb: running '%s'", sql_conflicts);
-
		ret = sqlite3_prepare_v2(db->sqlite, sql_conflicts, -1,
-
		    &stmt_conflicts, NULL);
-
		if (ret != SQLITE_OK) {
-
			ERROR_SQLITE(db->sqlite, sql_conflicts);
-
			sqlite3_finalize(stmt);
-
			sbuf_delete(conflictmsg);
-
			sbuf_delete(uniqueid);
-
			return (EPKG_FATAL);
-
		}
-

-
		sbuf_finish(uniqueid);
-

-
		sqlite3_bind_text(stmt_conflicts, 1,
-
		    sqlite3_column_text(stmt, 0), -1, SQLITE_STATIC);
-

-
		while (sqlite3_step(stmt_conflicts) != SQLITE_DONE) {
-
			/* Append UID of conflicting remote package */
-
			sbuf_printf(conflictmsg, "\t- %s\n",
-
			    sqlite3_column_text(stmt_conflicts, 0));
-
			if (cb != NULL)
-
				cb (sbuf_data(uniqueid), sqlite3_column_text(stmt_conflicts, 0), cbdata);
-
		}
-

-
		sbuf_finish(conflictmsg);
-
		sqlite3_finalize(stmt_conflicts);
-

-
		//pkg_emit_error("%s", sbuf_get(conflictmsg));
-
		retcode = EPKG_CONFLICT;
-
	}
-

-
	sqlite3_finalize(stmt);
-
	sbuf_delete(conflictmsg);
-
	sbuf_delete(uniqueid);
-

-
	assert (sql_exec(db->sqlite, "DROP TABLE IF EXISTS integritycheck") == EPKG_OK);
-

-
	return (retcode);
-
}
-

struct pkgdb_it *
pkgdb_integrity_conflict_local(struct pkgdb *db, const char *uniqueid)
{
modified libpkg/private/pkg.h
@@ -528,13 +528,6 @@ const char* packing_format_to_string(pkg_formats format);
int pkg_delete_files(struct pkg *pkg, unsigned force);
int pkg_delete_dirs(struct pkgdb *db, struct pkg *pkg);

-
typedef void (*conflict_func_cb)(const char *, const char *, void *);
-
int pkgdb_integrity_append(struct pkgdb *db, struct pkg *p,
-
		conflict_func_cb cb, void *cbdata);
-
int pkgdb_integrity_check(struct pkgdb *db, conflict_func_cb cb, void *cbdata);
-
struct pkgdb_it *pkgdb_integrity_conflict_local(struct pkgdb *db,
-
						const char *uniqueid);
-

int pkg_set_mtree(struct pkg *, const char *mtree);

/* pkgdb commands */