Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
More fixes to integrity checking.
Vsevolod Stakhov committed 12 years ago
commit f9320799ceb9e60b5be23c7f6605716d1a48fc6a
parent 4080fca
2 files changed +48 -37
modified libpkg/pkg_jobs.c
@@ -218,6 +218,8 @@ pkg_jobs_add_req(struct pkg_jobs *j, const char *origin, struct pkg *pkg,
	HASH_ADD_KEYPTR(hh, *head, origin, strlen(origin), req);
}

+
#define PRIORITY_SAME_SIGN(a, b) (((a) >= 0) ^ ((b) < 0))
+

static void
pkg_jobs_update_universe_priority(struct pkg_jobs *j,
		struct pkg_job_universe_item *item, int priority)
@@ -225,46 +227,55 @@ pkg_jobs_update_universe_priority(struct pkg_jobs *j,
	const char *origin;
	struct pkg_dep *d = NULL;
	struct pkg_conflict *c = NULL;
-
	struct pkg_job_universe_item *found, *cur;
+
	struct pkg_job_universe_item *found, *cur, *it;

	pkg_get(item->pkg, PKG_ORIGIN, &origin);

-
	pkg_debug(2, "universe: update priority of %s: %d -> %d",
+
	LL_FOREACH(item, it) {
+
		if (PRIORITY_SAME_SIGN(priority, it->priority)) {
+
			pkg_debug(2, "universe: update priority of %s: %d -> %d",
					origin, item->priority, priority);
-
	item->priority = priority;
-

-
	while (pkg_deps(item->pkg, &d) == EPKG_OK) {
-
		HASH_FIND_STR(j->universe, pkg_dep_get(d, PKG_DEP_ORIGIN), found);
-
		if (found != NULL) {
-
			LL_FOREACH(found, cur) {
-
				if (cur->priority < priority + 1)
-
					pkg_jobs_update_universe_priority(j, cur, priority + 1);
+
			it->priority = priority;
+

+
			while (pkg_deps(it->pkg, &d) == EPKG_OK) {
+
				HASH_FIND_STR(j->universe, pkg_dep_get(d, PKG_DEP_ORIGIN), found);
+
				if (found != NULL) {
+
					LL_FOREACH(found, cur) {
+
						if (PRIORITY_SAME_SIGN(priority, cur->priority) &&
+
								cur->priority < priority + 1)
+
							pkg_jobs_update_universe_priority(j, cur, priority + 1);
+
					}
+
				}
			}
-
		}
-
	}

-
	d = NULL;
-
	while (pkg_rdeps(item->pkg, &d) == EPKG_OK) {
-
		HASH_FIND_STR(j->universe, pkg_dep_get(d, PKG_DEP_ORIGIN), found);
-
		if (found != NULL) {
-
			LL_FOREACH(found, cur) {
-
				if (cur->priority > priority - 1)
-
					pkg_jobs_update_universe_priority(j, cur, priority - 1);
+
			d = NULL;
+
			while (pkg_rdeps(it->pkg, &d) == EPKG_OK) {
+
				HASH_FIND_STR(j->universe, pkg_dep_get(d, PKG_DEP_ORIGIN), found);
+
				if (found != NULL) {
+
					LL_FOREACH(found, cur) {
+
						if (PRIORITY_SAME_SIGN(priority, cur->priority) &&
+
								cur->priority > priority - 1)
+
							pkg_jobs_update_universe_priority(j, cur, priority - 1);
+
					}
+
				}
			}
-
		}
-
	}

-
	while (pkg_conflicts(item->pkg, &c) == EPKG_OK) {
-
		HASH_FIND_STR(j->universe, pkg_conflict_origin(c), found);
-
		if (found != NULL) {
-
			LL_FOREACH(found, cur) {
-
				if(cur->priority < priority)
-
					pkg_jobs_update_universe_priority(j, cur, priority);
+
			while (pkg_conflicts(it->pkg, &c) == EPKG_OK) {
+
				HASH_FIND_STR(j->universe, pkg_conflict_origin(c), found);
+
				if (found != NULL) {
+
					LL_FOREACH(found, cur) {
+
						if (PRIORITY_SAME_SIGN(priority, cur->priority) &&
+
								cur->priority < priority)
+
							pkg_jobs_update_universe_priority(j, cur, priority);
+
					}
+
				}
			}
		}
	}
}

+
#undef PRIORITY_SAME_SIGN
+

/**
 * Check whether a package is in the universe already or add it
 * @return item or NULL
@@ -1686,20 +1697,16 @@ pkg_jobs_check_conflicts(struct pkg_jobs *j)
			if (pkg_open(&pkg, path, keys, 0) != EPKG_OK)
				return (EPKG_FATAL);
		}
-
		if ((res = pkg_conflicts_append_pkg(pkg, j)) != EPKG_OK) {
+
		if ((res = pkg_conflicts_append_pkg(pkg, j)) != EPKG_OK)
			ret = res;
-
			if (ret == EPKG_FATAL)
-
				break;
-
		}
-
		else {
+
		else
			added ++;
-
		}
	}
	pkg_manifest_keys_free(keys);

	pkg_free(pkg);

-
	if (added > 0 && ret != EPKG_FATAL) {
+
	if (added > 0) {
		if ((res = pkg_conflicts_integrity_check(j)) != EPKG_OK) {
			pkg_emit_integritycheck_finished();
			return (res);
modified libpkg/pkgdb.c
@@ -3884,13 +3884,17 @@ pkgdb_integrity_check(struct pkgdb *db, conflict_func_cb cb, void *cbdata)
	const char	 sql_conflicts[] = ""
		"SELECT name, version, origin FROM integritycheck WHERE path = ?1;";

-
	if (sqlite3_prepare_v2(db->sqlite,
+
	const char sql_integrity_prepare[] = ""
		"SELECT path, COUNT(path) FROM ("
		"SELECT path FROM integritycheck UNION ALL "
		"SELECT path FROM files, main.packages AS p "
		"WHERE p.id = package_id AND p.origin NOT IN "
		"(SELECT origin FROM integritycheck)"
-
		") GROUP BY path HAVING (COUNT(path) > 1 );",
+
		") GROUP BY path HAVING (COUNT(path) > 1 );";
+

+
	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);
		return (EPKG_FATAL);
@@ -3980,7 +3984,7 @@ pkgdb_integrity_conflict_local(struct pkgdb *db, const char *origin)
		    "p.prefix "
		"FROM packages AS p, files AS f, integritycheck AS i "
		"WHERE p.id = f.package_id AND f.path = i.path "
-
		"AND i.origin = ?1";
+
		"AND i.origin = ?1 AND i.origin != p.origin";

	pkg_debug(4, "Pkgdb: running '%s'", sql_conflicts);
	ret = sqlite3_prepare_v2(db->sqlite, sql_conflicts, -1, &stmt, NULL);