Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Introduce flags for manifest emitting.
Vsevolod Stakhov committed 13 years ago
commit 9ea699b55fa585d4a90b4c39c8e85db128820c2c
parent 048232e
5 files changed +37 -31
modified libpkg/pkg.h.in
@@ -788,16 +788,20 @@ int pkg_load_manifest_file(struct pkg *pkg, const char *fpath, struct pkg_manife
int pkg_manifest_keys_new(struct pkg_manifest_key **k);
void pkg_manifest_keys_free(struct pkg_manifest_key *k);

+
#define PKG_MANIFEST_EMIT_COMPACT 0x1
+
#define PKG_MANIFEST_EMIT_NOFILES (0x1 << 1)
+

/**
 * Emit a manifest according to the attributes of pkg.
 * @param buf A pointer which will hold the allocated buffer containing the
 * manifest. To be free'ed.
+
 * @param flags Flags for manifest emitting.
 * @param pdigest A pointer that will hold digest of manifest produced, ignored
 * if NULL. To be free'ed if not NULL.
 * @return An error code.
 */
-
int pkg_emit_manifest(struct pkg *pkg, char **buf, bool compact, char **pdigest);
-
int pkg_emit_manifest_file(struct pkg*, FILE *, bool, char **pdigest);
+
int pkg_emit_manifest(struct pkg *pkg, char **buf, short flags, char **pdigest);
+
int pkg_emit_manifest_file(struct pkg*, FILE *, short, char **pdigest);

/* pkg_dep */
const char *pkg_dep_get(struct pkg_dep const * const , const pkg_dep_attr);
modified libpkg/pkg_create.c
@@ -105,7 +105,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,

		pkg_register_shlibs(pkg);

-
		pkg_emit_manifest_sbuf(pkg, b, false, NULL);
+
		pkg_emit_manifest_sbuf(pkg, b, 0, NULL);
		sbuf_finish(b);
		packing_append_buffer(pkg_archive, sbuf_data(b), "+MANIFEST", sbuf_len(b));
		sbuf_delete(b);
modified libpkg/pkg_manifest.c
@@ -928,7 +928,7 @@ pkg_emit_filelist(struct pkg *pkg, FILE *f)
}

static int
-
emit_manifest(struct pkg *pkg, yaml_emitter_t *emitter, bool compact)
+
emit_manifest(struct pkg *pkg, yaml_emitter_t *emitter, short flags)
{
	yaml_document_t doc;
	char tmpbuf[BUFSIZ];
@@ -1065,29 +1065,31 @@ emit_manifest(struct pkg *pkg, yaml_emitter_t *emitter, bool compact)
		    pkg_annotation_value(note), PLAIN);
	}

-
	if (!compact) {
+
	if ((flags & PKG_MANIFEST_EMIT_COMPACT) == 0) {
		map = -1;
-
		while (pkg_files(pkg, &file) == EPKG_OK) {
-
			const char *pkg_sum = pkg_file_cksum(file);
+
		if ((flags & PKG_MANIFEST_EMIT_NOFILES) == 0) {
+
			while (pkg_files(pkg, &file) == EPKG_OK) {
+
				const char *pkg_sum = pkg_file_cksum(file);

-
			if (pkg_sum == NULL || pkg_sum[0] == '\0')
-
				pkg_sum = "-";
+
				if (pkg_sum == NULL || pkg_sum[0] == '\0')
+
					pkg_sum = "-";

-
			if (map == -1)
-
				manifest_append_map(map, mapping, "files", BLOCK);
-
			urlencode(pkg_file_path(file), &tmpsbuf);
-
			manifest_append_kv(map, sbuf_get(tmpsbuf), pkg_sum, PLAIN);
-
		}
+
				if (map == -1)
+
					manifest_append_map(map, mapping, "files", BLOCK);
+
				urlencode(pkg_file_path(file), &tmpsbuf);
+
				manifest_append_kv(map, sbuf_get(tmpsbuf), pkg_sum, PLAIN);
+
			}

-
		seq = -1;
-
		map = -1;
-
		while (pkg_dirs(pkg, &dir) == EPKG_OK) {
-
			const char *try_str;
-
			if (map == -1)
-
				manifest_append_map(map, mapping, "directories", BLOCK);
-
			urlencode(pkg_dir_path(dir), &tmpsbuf);
-
			try_str = pkg_dir_try(dir) ? "y" : "n";
-
			manifest_append_kv(map, sbuf_get(tmpsbuf), try_str, PLAIN);
+
			seq = -1;
+
			map = -1;
+
			while (pkg_dirs(pkg, &dir) == EPKG_OK) {
+
				const char *try_str;
+
				if (map == -1)
+
					manifest_append_map(map, mapping, "directories", BLOCK);
+
				urlencode(pkg_dir_path(dir), &tmpsbuf);
+
				try_str = pkg_dir_try(dir) ? "y" : "n";
+
				manifest_append_kv(map, sbuf_get(tmpsbuf), try_str, PLAIN);
+
			}
		}

		map = -1;
@@ -1164,7 +1166,7 @@ pkg_emit_manifest_digest(const unsigned char *digest, size_t len, char *hexdiges
}

int
-
pkg_emit_manifest_file(struct pkg *pkg, FILE *f, bool compact, char **pdigest)
+
pkg_emit_manifest_file(struct pkg *pkg, FILE *f, short flags, char **pdigest)
{
	yaml_emitter_t emitter;
	struct pkg_yaml_emitter_data emitter_data;
@@ -1185,7 +1187,7 @@ pkg_emit_manifest_file(struct pkg *pkg, FILE *f, bool compact, char **pdigest)
	emitter_data.data.file = f;
	yaml_emitter_set_output(&emitter, yaml_write_file, &emitter_data);

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

	if (emitter_data.sign_ctx != NULL) {
		SHA256_Final(digest, emitter_data.sign_ctx);
@@ -1198,7 +1200,7 @@ pkg_emit_manifest_file(struct pkg *pkg, FILE *f, bool compact, char **pdigest)
}

int
-
pkg_emit_manifest_sbuf(struct pkg *pkg, struct sbuf *b, bool compact, char **pdigest)
+
pkg_emit_manifest_sbuf(struct pkg *pkg, struct sbuf *b, short flags, char **pdigest)
{
	yaml_emitter_t emitter;
	struct pkg_yaml_emitter_data emitter_data;
@@ -1219,7 +1221,7 @@ pkg_emit_manifest_sbuf(struct pkg *pkg, struct sbuf *b, bool compact, char **pdi
	emitter_data.data.sbuf = b;
	yaml_emitter_set_output(&emitter, yaml_write_buf, &emitter_data);

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

	if (emitter_data.sign_ctx != NULL) {
		SHA256_Final(digest, emitter_data.sign_ctx);
@@ -1233,12 +1235,12 @@ pkg_emit_manifest_sbuf(struct pkg *pkg, struct sbuf *b, bool compact, char **pdi
}

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

-
	rc = pkg_emit_manifest_sbuf(pkg, b, compact, pdigest);
+
	rc = pkg_emit_manifest_sbuf(pkg, b, flags, pdigest);

	if (rc != EPKG_OK) {
		sbuf_delete(b);
modified libpkg/pkg_repo.c
@@ -316,7 +316,7 @@ pkg_create_repo(char *path, bool force, void (progress)(struct pkg *pkg, void *d

		manifest_pos = ftell(psyml);
		files_pos = ftell(fsyml);
-
		pkg_emit_manifest_file(r->pkg, psyml, true, &manifest_digest);
+
		pkg_emit_manifest_file(r->pkg, psyml, PKG_MANIFEST_EMIT_COMPACT, &manifest_digest);
		pkg_emit_filelist(r->pkg, fsyml);

		pkg_get(r->pkg, PKG_ORIGIN, &origin);
modified libpkg/private/pkg.h
@@ -406,7 +406,7 @@ 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_manifest_sbuf(struct pkg*, struct sbuf *, bool, char **);
+
int pkg_emit_manifest_sbuf(struct pkg*, struct sbuf *, short, char **);
int pkg_emit_filelist(struct pkg *, FILE *);
int pkg_parse_manifest_archive(struct pkg *pkg, struct archive *a, struct pkg_manifest_key *keys);