Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
manifest: cleanup
Baptiste Daroussin committed 2 years ago
commit 959e2d62f7ba350e614ab13249439be6bee690e8
parent 6dd3c09
3 files changed +22 -66
modified libpkg/pkg_create.c
@@ -64,6 +64,8 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
	int64_t		 flatsize = 0;
	int64_t		 nfiles;
	const char	*relocation;
+
	char		*manifest;
+
	ucl_object_t	*obj;
	hardlinks_t	 hardlinks = tll_init();

	if (pkg_is_valid(pkg) != EPKG_OK) {
@@ -131,19 +133,20 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
	 * Register shared libraries used by the package if
	 * SHLIBS enabled in conf.  Deletes shlib info if not.
	 */
-
	xstring *b = xstring_new();
-

-
	pkg_emit_manifest_buf(pkg, b, PKG_MANIFEST_EMIT_COMPACT);
-
	fflush(b->fp);
-
	packing_append_buffer(pkg_archive, b->buf, "+COMPACT_MANIFEST", strlen(b->buf));
-
	xstring_reset(b);
-
	if (pc->expand_manifest)
-
		pkg_emit_manifest_buf(pkg, b, PKG_MANIFEST_EMIT_UCL);
-
	else
-
		pkg_emit_manifest_buf(pkg, b, 0);
-
	fflush(b->fp);
-
	packing_append_buffer(pkg_archive, b->buf, "+MANIFEST", strlen(b->buf));
-
	xstring_free(b);
+

+
	obj = pkg_emit_object(pkg, PKG_MANIFEST_EMIT_COMPACT);
+
	manifest = ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT);
+
	ucl_object_unref(obj);
+
	packing_append_buffer(pkg_archive, manifest, "+COMPACT_MANIFEST", strlen(manifest));
+
	free(manifest);
+
	obj = pkg_emit_object(pkg, 0);
+
	if (pc->expand_manifest) {
+
		manifest = ucl_object_emit(obj, UCL_EMIT_CONFIG);
+
	} else {
+
		manifest = ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT);
+
	}
+
	ucl_object_unref(obj);
+
	packing_append_buffer(pkg_archive, manifest, "+MANIFEST", strlen(manifest));

	counter_init("packing files", nfiles);

modified libpkg/pkg_manifest.c
@@ -1243,69 +1243,23 @@ pkg_emit_object(struct pkg *pkg, short flags)
	return (top);
}

-

-
static int
-
emit_manifest(struct pkg *pkg, xstring **out, short flags)
+
int
+
pkg_emit_manifest_file(struct pkg *pkg, FILE *out, short flags)
{
	ucl_object_t *top;

	top = pkg_emit_object(pkg, flags);

	if ((flags & PKG_MANIFEST_EMIT_PRETTY) == PKG_MANIFEST_EMIT_PRETTY)
-
		ucl_object_emit_buf(top, UCL_EMIT_YAML, out);
+
		ucl_object_emit_file(top, UCL_EMIT_YAML, out);
	else if ((flags & PKG_MANIFEST_EMIT_UCL) == PKG_MANIFEST_EMIT_UCL)
-
		ucl_object_emit_buf(top, UCL_EMIT_CONFIG, out);
+
		ucl_object_emit_file(top, UCL_EMIT_CONFIG, out);
	else if ((flags & PKG_MANIFEST_EMIT_JSON) == PKG_MANIFEST_EMIT_JSON)
-
		ucl_object_emit_buf(top, UCL_EMIT_JSON, out);
+
		ucl_object_emit_file(top, UCL_EMIT_JSON, out);
	else
-
		ucl_object_emit_buf(top, UCL_EMIT_JSON_COMPACT, out);
+
		ucl_object_emit_file(top, UCL_EMIT_JSON_COMPACT, out);

	ucl_object_unref(top);

	return (EPKG_OK);
}
-

-
/*
-
 * This routine is able to output to either a (FILE *) or a (struct sbuf *). It
-
 * exist only to avoid code duplication and should not be called except from
-
 * pkg_emit_manifest_file() and pkg_emit_manifest_buf().
-
 */
-
static int
-
pkg_emit_manifest_generic(struct pkg *pkg, void *out, short flags,
-
    bool out_is_a_buf)
-
{
-
	xstring *output = NULL;
-
	SHA256_CTX *sign_ctx = NULL;
-
	int rc;
-

-
	if (out_is_a_buf)
-
		output = out;
-

-
	rc = emit_manifest(pkg, &output, flags);
-

-
	fflush(output->fp);
-
	if (sign_ctx != NULL)
-
		sha256_update(sign_ctx, output->buf, strlen(output->buf));
-

-
	if (!out_is_a_buf)
-
		fprintf(out, "%s\n", output->buf);
-

-
	if (!out_is_a_buf)
-
		xstring_free(output);
-

-
	return (rc);
-
}
-

-
int
-
pkg_emit_manifest_file(struct pkg *pkg, FILE *f, short flags)
-
{
-

-
	return (pkg_emit_manifest_generic(pkg, f, flags, false));
-
}
-

-
int
-
pkg_emit_manifest_buf(struct pkg *pkg, xstring *b, short flags)
-
{
-

-
	return (pkg_emit_manifest_generic(pkg, b, flags, true));
-
}
modified libpkg/private/pkg.h
@@ -714,7 +714,6 @@ int pkgdb_set_pkg_digest(struct pkgdb *db, struct pkg *pkg);
int pkgdb_is_dir_used(struct pkgdb *db, struct pkg *p, const char *dir, int64_t *res);
int pkgdb_file_set_cksum(struct pkgdb *db, struct pkg_file *file, const char *sha256);

-
int pkg_emit_manifest_buf(struct pkg*, xstring *, short);
int pkg_emit_filelist(struct pkg *, FILE *);

bool ucl_object_emit_buf(const ucl_object_t *obj, enum ucl_emitter emit_type,