Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Resolve conflicts in a request.
Vsevolod Stakhov committed 12 years ago
commit a1daa5e7dafc3cdc6fb15259cafec533986a2fa6
parent 1694756
3 files changed +45 -63
modified libpkg/pkg_conflicts.c
@@ -45,11 +45,15 @@ pkg_conflicts_chain_cmp_cb(struct pkg_conflict_chain *a, struct pkg_conflict_cha
{
	const char *vera, *verb;

+
	if (a->req->skip || b->req->skip) {
+
		return (a->req->skip - b->req->skip);
+
	}
+

	pkg_get(a->req->pkg, PKG_VERSION, &vera);
	pkg_get(b->req->pkg, PKG_VERSION, &verb);

	/* Inverse sort to get the maximum version as the first element */
-
	return (pkg_version_cmp(verb, vera));
+
	return (pkg_version_cmp(vera, verb));
}

static int
@@ -81,6 +85,8 @@ pkg_conflicts_request_resolve_chain(struct pkg *req, struct pkg_conflict_chain *
		selected = chain;
	}

+
	pkg_get(selected->req->pkg, PKG_ORIGIN, &origin);
+
	pkg_debug(2, "select %s in the chain of conflicts for %s", origin, name);
	/* Disable conflicts from a request */
	LL_FOREACH(chain, elt) {
		if (elt != selected)
@@ -90,34 +96,48 @@ pkg_conflicts_request_resolve_chain(struct pkg *req, struct pkg_conflict_chain *
	return (EPKG_OK);
}

+
static void
+
pkg_conflicts_request_add_chain(struct pkg_conflict_chain **chain, struct pkg_job_request *req)
+
{
+
	struct pkg_conflict_chain *elt;
+

+
	elt = calloc(1, sizeof(struct pkg_conflict_chain));
+
	if (elt == NULL) {
+
		pkg_emit_errno("resolve_request_conflicts", "calloc: struct pkg_conflict_chain");
+
	}
+
	elt->req = req;
+
	LL_PREPEND(*chain, elt);
+
}
+

int
pkg_conflicts_request_resolve(struct pkg_jobs *j)
{
	struct pkg_job_request *req, *rtmp, *found;
	struct pkg_conflict *c, *ctmp;
-
	struct pkg_conflict_chain *chain, *elt;
+
	struct pkg_conflict_chain *chain;
+
	const char *origin;

	HASH_ITER(hh, j->request_add, req, rtmp) {
		chain = NULL;
+
		if (req->skip)
+
			continue;
+

		HASH_ITER(hh, req->pkg->conflicts, c, ctmp) {
			HASH_FIND_STR(j->request_add, pkg_conflict_origin(c), found);
			if (found && !found->skip) {
-
				elt = calloc(1, sizeof(struct pkg_conflict_chain));
-
				if (elt == NULL) {
-
					pkg_emit_errno("resolve_request_conflicts", "calloc: struct pkg_conflict_chain");
-
					return (EPKG_FATAL);
-
				}
-
				elt->req = found;
-
				LL_PREPEND(chain, elt);
+
				pkg_conflicts_request_add_chain(&chain, found);
			}
-
			if (chain != NULL) {
-
				/* We need to handle conflict chain here */
-
				if (pkg_conflicts_request_resolve_chain(req->pkg, chain) != EPKG_OK) {
-
					LL_FREE(chain, pkg_conflict_chain, free);
-
					return (EPKG_FATAL);
-
				}
+
		}
+
		if (chain != NULL) {
+
			pkg_get(req->pkg, PKG_ORIGIN, &origin);
+
			/* Add package itself */
+
			pkg_conflicts_request_add_chain(&chain, req);
+

+
			if (pkg_conflicts_request_resolve_chain(req->pkg, chain) != EPKG_OK) {
				LL_FREE(chain, pkg_conflict_chain, free);
+
				return (EPKG_FATAL);
			}
+
			LL_FREE(chain, pkg_conflict_chain, free);
		}
	}

modified libpkg/pkg_jobs.c
@@ -547,48 +547,6 @@ end:
}

static int
-
pkg_jobs_register_remote_conflicts(struct pkg_jobs *j, const char *origin, struct pkg *rp, int priority)
-
{
-
	struct pkg *lp;
-
	struct pkgdb_it *it = NULL;
-
	const char *lorigin;
-
	int lflags = PKG_LOAD_BASIC | PKG_LOAD_FILES | PKG_LOAD_SCRIPTS |
-
		    PKG_LOAD_DIRS;
-
	struct pkg_conflict *c1, *c2;
-

-
	it = pkgdb_integrity_conflict_local(j->db, origin);
-

-
	if (it != NULL) {
-
		lp = NULL;
-
		while (pkgdb_it_next(it, &lp, lflags) == EPKG_OK) {
-
			pkg_get(lp, PKG_ORIGIN, &lorigin);
-
			pkg_jobs_add_universe(j, lp, priority, true);
-
			/* Register conflicts */
-
			pkg_conflict_new(&c1);
-
			pkg_conflict_new(&c2);
-
			if (c1 != NULL && c2 != NULL) {
-
				sbuf_set(&c1->origin, lorigin);
-
				sbuf_set(&c2->origin, origin);
-
				pkg_debug(2, "registering conflict between remote %s and local %s", origin, lorigin);
-
				HASH_ADD_KEYPTR(hh, rp->conflicts, lorigin, strlen(lorigin), c1);
-
				HASH_ADD_KEYPTR(hh, lp->conflicts, origin, strlen(origin), c2);
-
			}
-

-
			/* Special case for locked packages */
-
			if (pkg_is_locked(lp)) {
-
				pkg_emit_locked(lp);
-
				pkgdb_it_free(it);
-
				return (EPKG_LOCKED);
-
			}
-
			lp = NULL;
-
		}
-
		pkgdb_it_free(it);
-
	}
-

-
	return (EPKG_OK);
-
}
-

-
static int
find_remote_pkg(struct pkg_jobs *j, const char *pattern, match_t m, bool root, int priority)
{
	struct pkg *p = NULL;
@@ -656,10 +614,8 @@ find_remote_pkg(struct pkg_jobs *j, const char *pattern, match_t m, bool root, i
		rc = EPKG_OK;
		p->direct = root;
		/* Add a package to request chain and populate universe */
-
		if (pkg_jobs_register_remote_conflicts(j, origin, p, priority) == EPKG_OK) {
-
			/* Do not request packages with a conflict with locked installed packages */
-
			pkg_jobs_add_req(j, origin, p, true, priority);
-
		}
+

+
		pkg_jobs_add_req(j, origin, p, true, priority);
		rc = pkg_jobs_add_universe(j, p, priority, true);


@@ -1444,8 +1400,8 @@ pkg_jobs_check_conflicts(struct pkg_jobs *j)
	pkg_free(pkg);

	if (ret != EPKG_FATAL) {
-
		if ((ret = pkg_conflicts_integrity_check(j)) != EPKG_OK)
-
			return (ret);
+
		if ((res = pkg_conflicts_integrity_check(j)) != EPKG_OK)
+
			return (res);
	}

	pkg_emit_integritycheck_finished();
modified libpkg/pkg_solve.c
@@ -557,6 +557,9 @@ pkg_solve_jobs_to_sat(struct pkg_jobs *j)

	/* Add requests */
	HASH_ITER(hh, j->request_add, jreq, jtmp) {
+
		if (jreq->skip)
+
			continue;
+

		rule = NULL;
		it = NULL;
		var = NULL;
@@ -581,6 +584,9 @@ pkg_solve_jobs_to_sat(struct pkg_jobs *j)
		problem->rules_count ++;
	}
	HASH_ITER(hh, j->request_delete, jreq, jtmp) {
+
		if (jreq->skip)
+
			continue;
+

		rule = NULL;
		it = NULL;
		var = NULL;