Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Load message from ucl.
Vsevolod Stakhov committed 10 years ago
commit 73772ce89e590b915794e707ab317e9a4ca03c6d
parent 6db1f28
4 files changed +69 -6
modified libpkg/pkg.c
@@ -195,7 +195,7 @@ pkg_vget(const struct pkg * restrict pkg, va_list ap)
			*va_arg(ap, const char **) = NULL;
			break;
		case PKG_MESSAGE:
-
			*va_arg(ap, const char **) = pkg->message;
+
			*va_arg(ap, const char **) = pkg->message ? pkg->message->str : NULL;
			break;
		case PKG_ARCH:
			*va_arg(ap, const char **) = pkg->arch;
@@ -329,7 +329,8 @@ pkg_vset(struct pkg *pkg, va_list ap)
			break;
		case PKG_MESSAGE:
			free(pkg->message);
-
			pkg->message = strdup(va_arg(ap, const char *));
+
			pkg->message = calloc(1, sizeof(*pkg->message));
+
			pkg->message->str = strdup(va_arg(ap, const char *));
			break;
		case PKG_ARCH:
			free(pkg->arch);
modified libpkg/pkg_create.c
@@ -283,6 +283,56 @@ 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)
+
{
+
	char *buf = NULL;
+
	char *cp;
+
	off_t size = 0;
+
	int ret = EPKG_OK;
+
	struct ucl_parser *parser;
+
	struct ucl_object *obj;
+

+
	assert(pkg != NULL);
+
	assert(path != NULL);
+

+
	if (faccessat(fd, path, F_OK, 0) == 0) {
+
		pkg_debug(1, "Reading message: '%s'", path);
+

+
		if ((ret = file_to_bufferat(fd, path, &buf, &size)) != EPKG_OK) {
+
			return (false);
+
		}
+

+
		if (is_ucl) {
+
			parser = ucl_parser_new(0);
+

+
			if (ucl_parser_add_chunk(parser, (const unsigned char*)buf, size)) {
+
				obj = ucl_parser_get_object(parser);
+
				ucl_parser_free(parser);
+
				free(buf);
+

+
				ret = pkg_message_from_ucl(pkg, obj);
+
				ucl_object_unref(obj);
+

+
				return (ret);
+
			}
+

+
			ucl_parser_free (parser);
+
			free(buf);
+
		}
+
		else {
+
			obj = ucl_object_fromlstring(buf, size);
+
			ret = pkg_message_from_ucl(pkg, obj);
+
			ucl_object_unref(obj);
+
			free(buf);
+

+
			return (ret);
+
		}
+
	}
+

+
	return (EPKG_FATAL);
+
}
+

int
pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir,
    const char *md_dir, char *plist)
@@ -325,8 +375,13 @@ pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir,
		pkg_load_from_file(mfd, pkg, PKG_DESC, "+DESC");

	/* if no message try to get it from a file */
-
	if (pkg->message == NULL)
-
		pkg_load_from_file(mfd, pkg, PKG_MESSAGE, "+DISPLAY");
+
	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);
+
		}
+
	}

	/* if no arch autodetermine it */
	if (pkg->abi == NULL) {
modified libpkg/pkg_manifest.c
@@ -552,8 +552,8 @@ pkg_obj(struct pkg *pkg, const ucl_object_t *obj, int attr)
	return (EPKG_OK);
}

-
static int
-
pkg_message(struct pkg *pkg, const ucl_object_t *obj, int attr)
+
int
+
pkg_message_from_ucl(struct pkg *pkg, const ucl_object_t *obj)
{
	struct pkg_message *msg;
	const ucl_object_t *elt;
@@ -592,6 +592,12 @@ pkg_message(struct pkg *pkg, const ucl_object_t *obj, int attr)
}

static int
+
pkg_message(struct pkg *pkg, const ucl_object_t *obj, int attr)
+
{
+
	return pkg_message_from_ucl(pkg, obj);
+
}
+

+
static int
pkg_set_files_from_object(struct pkg *pkg, const ucl_object_t *obj)
{
	const ucl_object_t *cur;
modified libpkg/private/pkg.h
@@ -731,5 +731,6 @@ int pkg_addoption_description(struct pkg *pkg, const char *key, const char *desc

int pkg_arch_to_legacy(const char *arch, char *dest, size_t sz);
bool pkg_is_config_file(struct pkg *p, const char *path, const struct pkg_file **file, struct pkg_config_file **cfile);
+
int pkg_message_from_ucl(struct pkg *pkg, const ucl_object_t *obj);

#endif