Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
install: emit a message when trying to install -f a locked package
Baptiste Daroussin committed 1 month ago
commit 46aa15eabf7b2db9db2372dfe820c37371677880
parent 0273291
2 files changed +54 -2
modified libpkg/pkg_jobs.c
@@ -804,8 +804,10 @@ pkg_jobs_process_remote_pkg(struct pkg_jobs *j, struct pkg *rp,
	}
	if (j->type != PKG_JOBS_FETCH) {
		lp = pkg_jobs_universe_get_local(j->universe, rp->uid, 0);
-
		if (lp && lp->locked)
+
		if (lp && lp->locked) {
+
			pkg_emit_locked(lp);
			return (EPKG_LOCKED);
+
		}
	}

	nit = pkg_jobs_universe_get_upgrade_candidates(j->universe, rp->uid, lp,
@@ -892,7 +894,7 @@ pkg_jobs_find_upgrade(struct pkg_jobs *j, const char *pattern, match_t m)

	pkgdb_it_free(it);

-
	if (!found && rc != EPKG_INSTALLED) {
+
	if (!found && rc != EPKG_INSTALLED && rc != EPKG_LOCKED) {
		/*
		 * Here we need to ensure that this package has no
		 * reverse deps installed
modified tests/frontend/lock.sh
@@ -5,6 +5,7 @@
tests_init \
	lock \
	lock_delete \
+
	lock_install_force \
	unlock_all

lock_setup() {
@@ -117,6 +118,55 @@ lock_delete_body() {
	    pkg lock -l
}

+
lock_install_force_body() {
+
	# Regression test for issue #2151: pkg install -f on a locked package
+
	# should warn that the package is locked instead of silently doing
+
	# nothing or printing a misleading message.
+

+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1 /usr/local
+

+
	# Create package and repo
+
	atf_check \
+
		-o ignore \
+
		-e empty \
+
		-s exit:0 \
+
		pkg create -M test.ucl
+

+
	atf_check \
+
		-o ignore \
+
		-e empty \
+
		-s exit:0 \
+
		pkg repo .
+

+
	mkdir reposconf
+
	cat << EOF > reposconf/repo.conf
+
local: {
+
	url: file:///$TMPDIR,
+
	enabled: true
+
}
+
EOF
+

+
	# Install the package
+
	atf_check \
+
		-o ignore \
+
		-s exit:0 \
+
		pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o PKG_CACHEDIR="${TMPDIR}" \
+
		install -y test
+

+
	# Lock it
+
	atf_check -o ignore -s exit:0 pkg lock -y test
+

+
	# pkg install -f should warn about the lock and fail
+
	atf_check \
+
		-o match:"locked" \
+
		-s exit:1 \
+
		pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o PKG_CACHEDIR="${TMPDIR}" \
+
		install -fy test
+

+
	# Package should still be installed
+
	atf_check -s exit:0 pkg info -e test
+
}
+

unlock_all_body()
{
	mkdir target