Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use the same hack as grabbing the message from the database to discover if +DISPLAY ia actually a ucl message or not
Baptiste Daroussin committed 10 years ago
commit 4486db6956cb64f61bad7bf7f1593c5bd83963d6
parent 9522377
4 files changed +67 -24
modified libpkg/pkg.c
@@ -305,6 +305,8 @@ pkg_vset(struct pkg *pkg, va_list ap)
{
	int attr;
	const char *buf;
+
	ucl_object_t *obj;
+
	struct pkg_message *msg;

	while ((attr = va_arg(ap, int)) > 0) {
		if (attr >= PKG_NUM_FIELDS || attr <= 0) {
@@ -339,9 +341,18 @@ pkg_vset(struct pkg *pkg, va_list ap)
			(void)va_arg(ap, const char *);
			break;
		case PKG_MESSAGE:
-
			pkg_message_free(pkg->message);
+
			LL_FOREACH(pkg->message, msg) {
+
				pkg_message_free(msg);
+
			}
			buf = va_arg(ap, const char *);
-
			pkg_message_from_str(pkg, buf, strlen(buf));
+
			if (*buf == '[') {
+
				pkg_message_from_str(pkg, buf, strlen(buf));
+
			} else {
+
				obj = ucl_object_fromstring_common(buf, strlen(buf),
+
				    UCL_STRING_RAW|UCL_STRING_TRIM);
+
				pkg_message_from_ucl(pkg, obj);
+
				ucl_object_unref(obj);
+
			}
			break;
		case PKG_ARCH:
			free(pkg->arch);
modified libpkg/pkg_create.c
@@ -284,7 +284,7 @@ pkg_load_from_file(int fd, struct pkg *pkg, pkg_attr attr, const char *path)
}

static int
-
pkg_load_message_from_file(int fd, struct pkg *pkg, const char *path, bool is_ucl)
+
pkg_load_message_from_file(int fd, struct pkg *pkg, const char *path)
{
	char *buf = NULL;
	off_t size = 0;
@@ -301,13 +301,11 @@ pkg_load_message_from_file(int fd, struct pkg *pkg, const char *path, bool is_uc
			return (ret);
		}

-
		if (is_ucl) {
+
		if (*buf == '[') {
			ret = pkg_message_from_str(pkg, buf, size);
			free(buf);
-

			return (ret);
-
		}
-
		else {
+
		} else {
			obj = ucl_object_fromstring_common(buf, size,
					UCL_STRING_RAW|UCL_STRING_TRIM);
			ret = pkg_message_from_ucl(pkg, obj);
@@ -365,10 +363,7 @@ pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir,
	/* if no message try to get it from a file */
	if (pkg->message == NULL) {
		/* Try ucl version first */
-
		if (pkg_load_message_from_file(mfd, pkg, "+DISPLAY.ucl", true)
-
				!= EPKG_OK) {
-
			pkg_load_message_from_file(mfd, pkg, "+DISPLAY", false);
-
		}
+
		pkg_load_message_from_file(mfd, pkg, "+DISPLAY");
	}

	/* if no arch autodetermine it */
modified tests/frontend/create.sh
@@ -385,24 +385,13 @@ EOF

OUTPUT='test-1:
Always:
-
[
-
	{ message: "message" },
-
	{ message: "message upgrade", type = "upgrade" },
-
]
-

-
'
-
	atf_check pkg create -m . -r ${TMPDIR}
-
	atf_check -o inline:"${OUTPUT}" pkg info -D -F ./test-1.txz
-

-
OUTPUT='test-1:
-
Always:
message

On upgrade:
message upgrade

'
-
	mv +DISPLAY +DISPLAY.ucl
+

	atf_check pkg create -m . -r ${TMPDIR}
	atf_check -o inline:"${OUTPUT}" pkg info -D -F ./test-1.txz

modified tests/frontend/register.sh
@@ -3,7 +3,8 @@
. $(atf_get_srcdir)/test_environment.sh

tests_init \
-
	register_conflicts
+
	register_conflicts \
+
	register_message

register_conflicts_body() {
	mkdir -p teststage/${TMPDIR}
@@ -54,3 +55,50 @@ EOF
	nsum=$(openssl dgst -sha256 -binary plop | hexdump -v -e '/1 "%x"')
	atf_check_equal ${sum} ${nsum}
}
+

+
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
+
	cat << EOF > +DISPLAY
+
message
+
EOF
+

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

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

+
	cat << EOF > +DISPLAY
+
[
+
	{ message: "hey"},
+
	{ message: "install", type = install},
+
	{ message: "remove", type = remove},
+
]
+
EOF
+
OUTPUT='test2-1:
+
Always:
+
hey
+

+
On install:
+
install
+

+
On remove:
+
remove
+

+
'
+
	atf_check -o match:"hey" -o match:"install" -o not-match:"remove" pkg register -m .
+
	atf_check -o inline:"${OUTPUT}" pkg info -D test2
+

+
}