Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
groups: export groups in the repo data
Baptiste Daroussin committed 2 years ago
commit 76fc5eb2e910e885529f633370af415443eaa651
parent e9a58f5
5 files changed +79 -17
modified external/libucl/src/ucl_emitter.c
@@ -1,4 +1,25 @@
-

+
/* Copyright (c) 2013, Vsevolod Stakhov
+
 * All rights reserved.
+
 *
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions are met:
+
 *       * Redistributions of source code must retain the above copyright
+
 *         notice, this list of conditions and the following disclaimer.
+
 *       * Redistributions in binary form must reproduce the above copyright
+
 *         notice, this list of conditions and the following disclaimer in the
+
 *         documentation and/or other materials provided with the distribution.
+
 *
+
 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
+
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+
 * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
+
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -235,9 +256,17 @@ ucl_emitter_common_start_array (struct ucl_emitter_context *ctx,
	bool first_key = true;

	if (ctx->id != UCL_EMIT_CONFIG && !first) {
-
		if (ctx->id == UCL_EMIT_YAML && ctx->indent == 0) {
-
			func->ucl_emitter_append_len ("\n", 1, func->ud);
+
		if (compact) {
+
			func->ucl_emitter_append_character (',', 1, func->ud);
		}
+
		else {
+
			if (ctx->id == UCL_EMIT_YAML && ctx->indent == 0) {
+
				func->ucl_emitter_append_len ("\n", 1, func->ud);
+
			} else {
+
				func->ucl_emitter_append_len (",\n", 2, func->ud);
+
			}
+
		}
+
		ucl_add_tabs (func, ctx->indent, compact);
	}

	ucl_emitter_print_key (print_key, ctx, obj, compact);
@@ -287,9 +316,17 @@ ucl_emitter_common_start_object (struct ucl_emitter_context *ctx,
	bool first_key = true;

	if (ctx->id != UCL_EMIT_CONFIG && !first) {
-
		if (ctx->id == UCL_EMIT_YAML && ctx->indent == 0) {
-
			func->ucl_emitter_append_len ("\n", 1, func->ud);
+
		if (compact) {
+
			func->ucl_emitter_append_character (',', 1, func->ud);
+
		}
+
		else {
+
			if (ctx->id == UCL_EMIT_YAML && ctx->indent == 0) {
+
				func->ucl_emitter_append_len ("\n", 1, func->ud);
+
			} else {
+
				func->ucl_emitter_append_len (",\n", 2, func->ud);
+
			}
		}
+
		ucl_add_tabs (func, ctx->indent, compact);
	}

	ucl_emitter_print_key (print_key, ctx, obj, compact);
@@ -358,15 +395,13 @@ ucl_emitter_common_elt (struct ucl_emitter_context *ctx,

	if (ctx->id != UCL_EMIT_CONFIG && !first) {
		if (compact) {
-
			if (ctx->indent > 0)
-
				func->ucl_emitter_append_character (',', 1, func->ud);
+
			func->ucl_emitter_append_character (',', 1, func->ud);
		}
		else {
			if (ctx->id == UCL_EMIT_YAML && ctx->indent == 0) {
				func->ucl_emitter_append_len ("\n", 1, func->ud);
			} else {
-
				if (ctx->indent > 0)
-
					func->ucl_emitter_append_len (",\n", 2, func->ud);
+
				func->ucl_emitter_append_len (",\n", 2, func->ud);
			}
		}
	}
modified libpkg/pkg_repo_create.c
@@ -810,6 +810,14 @@ pkg_repo_create(struct pkg_repo_create *prc, char *path)

	struct ucl_emitter_functions *f;
	ucl_object_t *obj = ucl_object_typed_new(UCL_OBJECT);
+
	/*
+
	 * Work around a bug in the streamline exporter which creates an invalid
+
	 * json if there is nothing in the object, prior to the streamline to
+
	 * start. So always add at least an empty groups array
+
	 */
+
	ucl_object_insert_key(obj,
+
	    prc->groups == NULL ? ucl_object_typed_new(UCL_ARRAY) : prc->groups,
+
	    "groups", 0, false);
	f = ucl_object_emit_fd_funcs(te.dfd);
	te.ctx = ucl_object_emit_streamline_new(obj, UCL_EMIT_JSON_COMPACT, f);
	ucl_object_t *ar = ucl_object_typed_new(UCL_ARRAY);
@@ -832,15 +840,8 @@ pkg_repo_create(struct pkg_repo_create *prc, char *path)

	for (int i = 0; i < num_workers; i++)
		pthread_join(threads[i], NULL);
-
	pkg_emit_progress_tick(len, len);
-
	ucl_object_emit_streamline_end_container(te.ctx);
	ucl_object_emit_streamline_end_container(te.ctx);
-
	if (prc->groups != NULL) {
-
		prc->groups->key = "groups";
-
		prc->groups->keylen = sizeof("groups") -1;
-
		ucl_object_emit_streamline_start_container(te.ctx, prc->groups);
-
		ucl_object_emit_streamline_end_container(te.ctx);
-
	}
+
	pkg_emit_progress_tick(len, len);
	ucl_object_emit_streamline_finish(te.ctx);
	ucl_object_emit_funcs_free(f);
	ucl_object_unref(obj);
modified libpkg/repo/binary/binary_private.h
@@ -672,5 +672,6 @@ void pkg_repo_binary_finalize_prstatements(void);
 * Warning: returns a pointer to static array
 */
const char * pkg_repo_binary_get_filename(const char *name);
+
const char * pkg_repo_binary_get_groups_filename(const char *name);

#endif /* INIT_PRIVATE_H_ */
modified libpkg/repo/binary/common.c
@@ -230,6 +230,17 @@ pkg_repo_binary_run_prstatement(sql_prstmt_index s, ...)
	return (retcode);
}

+
const char *
+
pkg_repo_binary_get_groups_filename(const char *name)
+
{
+
	static char buf[MAXPATHLEN];
+

+
	snprintf(buf, sizeof(buf), REPO_NAME_PREFIX "%s-groups.ucl",
+
			name);
+

+
	return (buf);
+
}
+


const char *
pkg_repo_binary_get_filename(const char *name)
modified libpkg/repo/binary/update.c
@@ -619,6 +619,20 @@ pkg_repo_binary_update_proceed(const char *name, struct pkg_repo *repo,
				break;
		}
		pkg_emit_progress_tick(nbel, cnt);
+
		ucl_object_t *groups = ucl_object_ref(ucl_object_find_key(data, "groups"));
+
		if (groups != NULL) {
+
			int fd = openat(pkg_get_dbdirfd(),
+
			    pkg_repo_binary_get_groups_filename(repo->name),
+
			    O_CREAT|O_TRUNC|O_RDWR, 0644);
+
			if (fd != -1) {
+
				ucl_object_emit_fd(groups, UCL_EMIT_JSON_COMPACT, fd);
+
				close(fd);
+
			} else {
+
				pkg_emit_errno("openat",
+
				    pkg_repo_binary_get_groups_filename(repo->name));
+
			}
+

+
		}
	}

	if (rc == EPKG_OK)