Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Finish vital implementation with regression tests:
Baptiste Daroussin committed 10 years ago
commit 902b4c23f7e050c19f3787ed24cb02f8d4e35e62
parent c024637
5 files changed +61 -5
modified libpkg/pkg_jobs.c
@@ -1985,12 +1985,14 @@ pkg_jobs_execute(struct pkg_jobs *j)
	DL_FOREACH(j->jobs, ps) {
		switch (ps->type) {
		case PKG_SOLVED_DELETE:
-
		case PKG_SOLVED_UPGRADE_REMOVE:
			p = ps->items[0]->pkg;
-
			if (ps->type == PKG_SOLVED_DELETE && p->vital == 1) {
-
				pkg_emit_error("Cannot delete vital pkgs!");
-
				continue;
+
			if (ps->type == PKG_SOLVED_DELETE && p->vital && ((flags & PKG_DELETE_FORCE) == 0)) {
+
				pkg_emit_error("Cannot delete vital pkg: %s!", p->name);
+
				retcode = EPKG_FATAL;
+
				goto cleanup;
			}
+
			/* FALLTHROUGH*/
+
		case PKG_SOLVED_UPGRADE_REMOVE:
			if (ps->type == PKG_SOLVED_DELETE &&
			    (strcmp(p->name, "pkg") == 0 ||
			    strcmp(p->name, "pkg-devel") == 0) &&
modified libpkg/pkg_manifest.c
@@ -1013,6 +1013,9 @@ pkg_emit_object(struct pkg *pkg, short flags)
	if (pkg->pkgsize > 0)
		ucl_object_insert_key(top, ucl_object_fromint(pkg->pkgsize), "pkgsize", 7, false);

+
	if (pkg->vital)
+
		ucl_object_insert_key(top, ucl_object_frombool(pkg->vital), "vital", 5, false);
+

	if (pkg->desc != NULL) {
		urlencode(pkg->desc, &tmpsbuf);
		ucl_object_insert_key(top,
modified tests/Makefile.am
@@ -106,6 +106,7 @@ tests_scripts= \
		frontend/search.sh \
		frontend/set.sh \
		frontend/version.sh \
+
		frontend/vital.sh \
		frontend/test_environment.sh \
		frontend/issue1374.sh

modified tests/frontend/Kyuafile.in
@@ -33,5 +33,5 @@ atf_test_program{name='rubypuppet'}
atf_test_program{name='search'}
atf_test_program{name='set'}
atf_test_program{name='version'}
-

+
atf_test_program{name='vital'}
atf_test_program{name='issue1374'}
added tests/frontend/vital.sh
@@ -0,0 +1,50 @@
+
#!/usr/bin/env atf-sh
+

+
. $(atf_get_srcdir)/test_environment.sh
+

+
tests_init \
+
	vital
+

+
vital_body()
+
{
+
	new_pkg "test" "test" "1" || atf_fail "plop"
+
	cat << EOF >> test.ucl
+
vital = true;
+
EOF
+

+
	atf_check \
+
		-o empty \
+
		-e empty \
+
		-s exit:0 \
+
		pkg create -M test.ucl
+

+
	atf_check \
+
		-o match:"^vital" \
+
		-e empty \
+
		-s exit:0 \
+
		pkg info -R --raw-format ucl -F ${TMPDIR}/test-1.txz
+

+
	mkdir ${TMPDIR}/target
+
	atf_check \
+
		-o empty \
+
		-e empty \
+
		-s exit:0 \
+
		pkg -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.txz
+

+
	atf_check \
+
		-o inline:"1\n" \
+
		-e empty \
+
		-s exit:0 \
+
		pkg -r ${TMPDIR}/target query "%V" test
+

+
	atf_check \
+
		-o empty \
+
		-e inline:"pkg: Cannot delete vital pkg: test!\n" \
+
		-s exit:3 \
+
		pkg -r ${TMPDIR}/target delete -qy test
+
	atf_check \
+
		-o empty \
+
		-e empty \
+
		-s exit:0 \
+
		pkg -r ${TMPDIR}/target delete -qyf test
+
}