Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
config: Always error if we have duplicate config entries.
Emmanuel Vadot committed 4 years ago
commit 421baf807c1ce70139adcd7de6f2a2a10fa47f45
parent 78727ce
3 files changed +33 -9
modified libpkg/pkg.c
@@ -710,12 +710,8 @@ pkg_addconfig_file(struct pkg *pkg, const char *path, const char *content)
	pkg_debug(3, "Pkg: add new config file '%s'", path);

	if (pkghash_get(pkg->config_files_hash, path) != NULL) {
-
		if (ctx.developer_mode) {
-
			pkg_emit_error("duplicate file listing: %s, fatal (developer mode)", path);
-
			return (EPKG_FATAL);
-
		} else {
-
			pkg_emit_error("duplicate file listing: %s, ignoring", path);
-
		}
+
		pkg_emit_error("duplicate file listing: %s", path);
+
		return (EPKG_FATAL);
	}
	f = xcalloc(1, sizeof(*f));
	strlcpy(f->path, path, sizeof(f->path));
modified libpkg/pkg_manifest.c
@@ -414,6 +414,7 @@ pkg_array(struct pkg *pkg, const ucl_object_t *obj, uint32_t attr)
{
	const ucl_object_t *cur;
	ucl_object_iter_t it = NULL;
+
	int ret;

	pkg_debug(3, "%s", "Manifest: parsing array");
	while ((cur = ucl_iterate_object(obj, &it, true))) {
@@ -483,8 +484,11 @@ pkg_array(struct pkg *pkg, const ucl_object_t *obj, uint32_t attr)
		case PKG_CONFIG_FILES:
			if (cur->type != UCL_STRING)
				pkg_emit_error("Skipping malformed config file name");
-
			else
-
				pkg_addconfig_file(pkg, ucl_object_tostring(cur), NULL);
+
			else {
+
				ret = pkg_addconfig_file(pkg, ucl_object_tostring(cur), NULL);
+
				if (ret != EPKG_OK)
+
					return (ret);
+
			}
			break;
		case PKG_REQUIRES:
			if (cur->type != UCL_STRING)
@@ -778,6 +782,7 @@ parse_manifest(struct pkg *pkg, struct pkg_manifest_key *keys, ucl_object_t *obj
	ucl_object_iter_t it = NULL;
	struct pkg_manifest_key *selected_key;
	const char *key;
+
	int ret = EPKG_OK;

	while ((cur = ucl_iterate_object(obj, &it, true))) {
		key = ucl_object_key(cur);
@@ -790,7 +795,9 @@ parse_manifest(struct pkg *pkg, struct pkg_manifest_key *keys, ucl_object_t *obj
		}
		if (selected_key != NULL) {
			if (TYPE_SHIFT(ucl_object_type(cur)) & selected_key->valid_type) {
-
				selected_key->parse_data(pkg, cur, selected_key->type);
+
				ret = selected_key->parse_data(pkg, cur, selected_key->type);
+
				if (ret != EPKG_OK)
+
					return (ret);
			} else {
				pkg_emit_error("Skipping malformed key '%s'", key);
			}
modified tests/frontend/configmerge.sh
@@ -3,6 +3,7 @@
. $(atf_get_srcdir)/test_environment.sh
tests_init \
	config \
+
	config_duplicate \
	config_fileexist \
	config_filenotexist \
	config_fileexist_notinpkg \
@@ -50,6 +51,26 @@ config_body()
		cat ${TMPDIR}/target/${TMPDIR}/a
}

+
config_duplicate_body()
+
{
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
+
	cat >> test.ucl << EOF
+
files: {
+
	"${TMPDIR}/a": "$sum"
+
}
+

+
config: [
+
	"${TMPDIR}/a",
+
	"${TMPDIR}/a"
+
]
+
EOF
+

+
	echo "entry" > a
+

+
	atf_check -s exit:1 -e match:"pkg: duplicate file listing: .*" \
+
		pkg create -M test.ucl
+
}
+

config_fileexist_body()
{
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"