Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Allow to directly write manifest into a FILE * or a struct sbuf *
Baptiste Daroussin committed 13 years ago
commit 91b9c361bd18961c9c7050a466ed21951cda2003
parent 3a52068
3 files changed +59 -36
modified libpkg/pkg_manifest.c
@@ -773,30 +773,9 @@ pkg_emit_filelist(struct pkg *pkg, FILE *f)
	return (rc);
}

-
int
-
pkg_emit_manifest(struct pkg *pkg, char **dest, bool compact)
-
{
-
	struct sbuf *b = sbuf_new_auto();
-
	int rc;
-

-
	rc = pkg_emit_manifest2(pkg, b, compact);
-

-
	if (rc != EPKG_OK) {
-
		sbuf_delete(b);
-
		return (rc);
-
	}
-

-
	sbuf_finish(b);
-
	*dest = strdup(sbuf_get(b));
-
	sbuf_delete(b);
-

-
	return (rc);
-
}
-

-
int
-
pkg_emit_manifest2(struct pkg *pkg, struct sbuf *destbuf, bool compact)
+
static int
+
emit_manifest(struct pkg *pkg, yaml_emitter_t *emitter, bool compact)
{
-
	yaml_emitter_t emitter;
	yaml_document_t doc;
	char tmpbuf[BUFSIZ];
	struct pkg_dep *dep = NULL;
@@ -824,11 +803,6 @@ pkg_emit_manifest2(struct pkg *pkg, struct sbuf *destbuf, bool compact)
	lic_t licenselogic;
	int64_t flatsize, pkgsize;

-
	sbuf_reset(destbuf);
-
	yaml_emitter_initialize(&emitter);
-
	yaml_emitter_set_unicode(&emitter, 1);
-
	yaml_emitter_set_output(&emitter, yaml_write_buf, destbuf);
-

#define manifest_append_map(id, map, key, block) do {			\
	int scalar_obj = YAML_ADD_SCALAR(&doc, key, PLAIN);		\
	id = yaml_document_add_mapping(&doc, NULL, YAML_##block##_MAPPING_STYLE); \
@@ -1008,11 +982,64 @@ pkg_emit_manifest2(struct pkg *pkg, struct sbuf *destbuf, bool compact)
		    LITERAL);
	}

-
	if (!yaml_emitter_dump(&emitter, &doc))
+
	if (!yaml_emitter_dump(emitter, &doc))
		rc = EPKG_FATAL;

	sbuf_free(tmpsbuf);

+
	return (rc);
+
}
+

+
int
+
pkg_emit_manifest_file(struct pkg *pkg, FILE *f, bool compact)
+
{
+
	yaml_emitter_t emitter;
+
	int rc;
+

+
	yaml_emitter_initialize(&emitter);
+
	yaml_emitter_set_unicode(&emitter, 1);
+
	yaml_emitter_set_output_file(&emitter, f);
+

+
	rc = emit_manifest(pkg, &emitter, compact);
+

+
	yaml_emitter_delete(&emitter);
+

+
	return (rc);
+
}
+

+
int
+
pkg_emit_manifest_sbuf(struct pkg *pkg, struct sbuf *b, bool compact)
+
{
+
	yaml_emitter_t emitter;
+
	int rc;
+

+
	yaml_emitter_initialize(&emitter);
+
	yaml_emitter_set_unicode(&emitter, 1);
+
	yaml_emitter_set_output(&emitter, yaml_write_buf, b);
+

+
	rc = emit_manifest(pkg, &emitter, compact);
+

	yaml_emitter_delete(&emitter);
+

+
	return (rc);
+
}
+
int
+
pkg_emit_manifest(struct pkg *pkg, char **dest, bool compact)
+
{
+
	struct sbuf *b = sbuf_new_auto();
+
	int rc;
+

+
	rc = pkg_emit_manifest_sbuf(pkg, b, compact);
+

+
	if (rc != EPKG_OK) {
+
		sbuf_delete(b);
+
		return (rc);
+
	}
+

+
	sbuf_finish(b);
+
	*dest = strdup(sbuf_get(b));
+
	sbuf_delete(b);
+

	return (rc);
}
+

modified libpkg/pkg_repo.c
@@ -586,7 +586,6 @@ pkg_create_repo(char *path, __unused bool force, void (progress)(struct pkg *pkg
	char repodb[MAXPATHLEN + 1];
	char repopack[MAXPATHLEN + 1];
	FILE *psyml, *fsyml;
-
	struct sbuf *buf = sbuf_new_auto();

	psyml = fsyml = NULL;

@@ -691,9 +690,7 @@ pkg_create_repo(char *path, __unused bool force, void (progress)(struct pkg *pkg
		if (progress != NULL)
			progress(r->pkg, data);

-
		pkg_emit_manifest2(r->pkg, buf, true);
-
		sbuf_finish(buf);
-
		(void)fprintf(psyml, "%s", sbuf_data(buf));
+
		pkg_emit_manifest_file(r->pkg, psyml, true);
		pkg_emit_filelist(r->pkg, fsyml);

		pkg_get(r->pkg, PKG_ORIGIN, &origin, PKG_NAME, &name,
@@ -845,8 +842,6 @@ cleanup:
	if (fts != NULL)
		fts_close(fts);

-
	sbuf_delete(buf);
-

	finalize_prepared_statements();

	if (fsyml != NULL)
modified libpkg/private/pkg.h
@@ -383,7 +383,8 @@ int pkg_register_shlibs(struct pkg *pkg);

void pkg_config_parse(yaml_document_t *doc, yaml_node_t *node, struct pkg_config *conf_by_key);

-
int pkg_emit_manifest2(struct pkg*, struct sbuf *, bool);
+
int pkg_emit_manifest_sbuf(struct pkg*, struct sbuf *, bool);
+
int pkg_emit_manifest_file(struct pkg*, FILE *, bool);
int pkg_emit_filelist(struct pkg *, FILE *);

#endif