Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
vital: now explicitly state the SAT solver issue are due to a vital package
Baptiste Daroussin committed 22 days ago
commit 09da7c26cb3f4456ef979dd838788f127f1a5829
parent a15fddb
2 files changed +70 -2
modified libpkg/pkg_solve.c
@@ -1112,9 +1112,37 @@ reiterate:
			}
			xstring_free(sb);
		} else {
-
			pkg_emit_notice("Cannot solve problem using SAT solver, trying another plan");
			var = &problem->variables[abs(*failed) - 1];

+
			/* Check if the failure is caused by a vital package */
+
			bool vital_found = false;
+
			vec_rforeach(problem->rules, vj) {
+
				struct pkg_solve_rule *vrule = problem->rules.d[vj];
+
				if (vrule->reason != PKG_RULE_DEPEND)
+
					continue;
+
				/* In depend rules, the key element (inverse == -1) is the
+
				 * dependent package, positive items are its dependencies */
+
				struct pkg_solve_item *dep_pkg = NULL;
+
				bool depends_on_var = false;
+
				LL_FOREACH(vrule->items, item) {
+
					if (item->inverse == -1)
+
						dep_pkg = item;
+
					else if (item->var->uid == var->uid ||
+
					    STREQ(item->var->uid, var->uid))
+
						depends_on_var = true;
+
				}
+
				if (dep_pkg != NULL && depends_on_var &&
+
				    dep_pkg->var->unit->pkg->vital) {
+
					pkg_emit_error("Cannot remove %s: "
+
					    "required by vital package %s",
+
					    var->uid, dep_pkg->var->uid);
+
					vital_found = true;
+
				}
+
			}
+
			if (!vital_found)
+
				pkg_emit_notice("Cannot solve problem using SAT "
+
				    "solver, trying another plan");
+

			var->flags |= PKG_VAR_FAILED;

			need_reiterate = true;
modified tests/frontend/vital.sh
@@ -3,7 +3,8 @@
. $(atf_get_srcdir)/test_environment.sh

tests_init \
-
	vital
+
	vital \
+
	vital_dep_remove_message

vital_body()
{
@@ -49,3 +50,42 @@ EOF
		-s exit:0 \
		pkg -r ${TMPDIR}/target delete -qyf test
}
+

+
vital_dep_remove_message_body()
+
{
+
	# vital_pkg depends on dep; removing dep should produce
+
	# an informative error mentioning the vital package.
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "dep" "dep" "1"
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "vital_pkg" "vital_pkg" "1"
+
	cat << EOF >> vital_pkg.ucl
+
vital = true;
+
deps: {
+
	dep {
+
		origin: dep,
+
		version: "1"
+
	}
+
}
+
EOF
+

+
	atf_check -o ignore pkg register -M dep.ucl
+
	atf_check -o ignore pkg register -M vital_pkg.ucl
+

+
	# Removing dep should fail with a message about vital_pkg
+
	atf_check \
+
		-e match:"Cannot remove dep: required by vital package vital_pkg" \
+
		-s exit:1 \
+
		pkg delete -qy dep
+

+
	# dep should still be installed
+
	atf_check -s exit:0 pkg info -e dep
+

+
	# vital_pkg should still be installed
+
	atf_check -s exit:0 pkg info -e vital_pkg
+

+
	# Force remove should still work
+
	atf_check \
+
		-o empty \
+
		-e empty \
+
		-s exit:0 \
+
		pkg delete -qyf dep
+
}