Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix duplicate pkg registration overwriting the existing pkg
Brad Davis committed 8 years ago
commit ebd5b302656128e105a5ca430839f13d9de2296e
parent 3bbd9b3
3 files changed +36 -30
modified libpkg/pkg_ports.c
@@ -1289,6 +1289,10 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,
	UT_string *message;
	struct pkg_message *msg;

+
	if (pkg_is_installed(db, pkg->name) != EPKG_END) {
+
		return(EPKG_INSTALLED);
+
	}
+

	location = reloc;
	if (ctx.pkg_rootdir != NULL)
		location = ctx.pkg_rootdir;
modified tests/frontend/config.sh
@@ -3,31 +3,19 @@
. $(atf_get_srcdir)/test_environment.sh
tests_init \
	empty_conf \
+
	duplicate_pkgs_notallowed \
	inline_repo \
	nameserver
-
	#duplicate_pkgs
+
#	duplicate_pkgs_allowed \

-
# This test is half finished to show problems with `pkg register'
-
duplicate_pkgs_body() {
+
duplicate_pkgs_allowed_body() {
	cat << EOF > pkg.conf
duplicatedefault: 2
EOF

	for n in 1 2; do
-
		cat << EOF > test${n}.ucl
-
name: test
-
origin: test
-
version: ${n}
-
allowduplicate: true
-
maintainer: test
-
categories: [test]
-
comment: a test
-
www: http://test
-
prefix: /
-
desc: <<EOD
-
Yet another test
-
EOD
-
EOF
+
		new_pkg test${n} test ${n}
+
		echo 'allowduplicate: true' >> test${n}.ucl

	atf_check \
		-e empty \
@@ -44,6 +32,29 @@ done
		pkg info
}

+
duplicate_pkgs_notallowed_body() {
+
	for n in 1 2; do
+
		new_pkg test${n} test ${n}
+
	done
+

+
	atf_check \
+
		-e empty \
+
		-o match:"Installing test-1..." \
+
		-s exit:0 \
+
		pkg register -M test1.ucl
+

+
	atf_check \
+
		-e empty \
+
		-s exit:70 \
+
		pkg register -M test1.ucl
+

+
	atf_check \
+
		-e empty \
+
		-o match:"test-1                         a test" \
+
		-s exit:0 \
+
		pkg info
+
}
+

empty_conf_body() {
	touch pkg.conf

modified tests/frontend/register.sh
@@ -58,29 +58,20 @@ EOF
}

register_message_body() {
-
	cat << EOF > +MANIFEST
-
name: "test2"
-
origin: "osef"
-
version: "1"
-
arch: "freebsd:*"
-
maintainer: "non"
-
prefix: "${TMPDIR}"
-
www: "unknown"
-
comment: "need one"
-
desc: "here as well"
-
EOF
+
	new_manifest test1 1 "${TMPDIR}"
	cat << EOF > +DISPLAY
message
EOF

-
OUTPUT='test2-1:
+
OUTPUT='test1-1:
Always:
message

'
	atf_check -o match:"message" pkg register -m .
-
	atf_check -o inline:"${OUTPUT}" pkg info -D test2
+
	atf_check -o inline:"${OUTPUT}" pkg info -D test1

+
	new_manifest test2 1 "${TMPDIR}"
	cat << EOF > +DISPLAY
[
	{ message: "hey"},