Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Only insert valid data into the top ucl_object when emitting manifests
Baptiste Daroussin committed 12 years ago
commit 66c9b90ed4016fb02fb7f0a33a77e72ec92c0bd7
parent bb0dba3
1 file changed +42 -21
modified libpkg/pkg_manifest.c
@@ -860,16 +860,26 @@ emit_manifest(struct pkg *pkg, struct sbuf **out, short flags)
	    PKG_CKSUM, &pkgsum, PKG_PKGSIZE, &pkgsize);

	pkg_debug(4, "Emitting basic metadata");
-
	top = ucl_object_insert_key(top, ucl_object_fromstring(name), "name", 4, false);
-
	top = ucl_object_insert_key(top, ucl_object_fromstring(pkgorigin), "origin", 6, false);
-
	top = ucl_object_insert_key(top, ucl_object_fromstring(version), "version", 7, false);
-
	top = ucl_object_insert_key(top, ucl_object_fromstring_common(comment, 0, UCL_STRING_TRIM), "comment", 7, false);
-
	top = ucl_object_insert_key(top, ucl_object_fromstring(pkgarch), "arch", 4, false);
-
	top = ucl_object_insert_key(top, ucl_object_fromstring(pkgmaintainer), "maintainer", 10, false);
-
	top = ucl_object_insert_key(top, ucl_object_fromstring(prefix), "prefix", 6, false);
-
	top = ucl_object_insert_key(top, ucl_object_fromstring(www), "www", 3, false);
-
	top = ucl_object_insert_key(top, ucl_object_fromstring(repopath), "path", 4, false);
-
	top = ucl_object_insert_key(top, ucl_object_fromstring(pkgsum), "sum", 3, false);
+
	if (name)
+
		top = ucl_object_insert_key(top, ucl_object_fromstring(name), "name", 4, false);
+
	if (pkgorigin)
+
		top = ucl_object_insert_key(top, ucl_object_fromstring(pkgorigin), "origin", 6, false);
+
	if (version)
+
		top = ucl_object_insert_key(top, ucl_object_fromstring(version), "version", 7, false);
+
	if (comment)
+
		top = ucl_object_insert_key(top, ucl_object_fromstring_common(comment, 0, UCL_STRING_TRIM), "comment", 7, false);
+
	if (pkgarch)
+
		top = ucl_object_insert_key(top, ucl_object_fromstring(pkgarch), "arch", 4, false);
+
	if (pkgmaintainer)
+
		top = ucl_object_insert_key(top, ucl_object_fromstring(pkgmaintainer), "maintainer", 10, false);
+
	if (prefix)
+
		top = ucl_object_insert_key(top, ucl_object_fromstring(prefix), "prefix", 6, false);
+
	if (www)
+
		top = ucl_object_insert_key(top, ucl_object_fromstring(www), "www", 3, false);
+
	if (repopath)
+
		top = ucl_object_insert_key(top, ucl_object_fromstring(repopath), "path", 4, false);
+
	if (pkgsum)
+
		top = ucl_object_insert_key(top, ucl_object_fromstring(pkgsum), "sum", 3, false);

	switch (licenselogic) {
	case LICENSE_SINGLE:
@@ -905,7 +915,8 @@ emit_manifest(struct pkg *pkg, struct sbuf **out, short flags)
		submap = ucl_object_insert_key(submap, ucl_object_fromstring(pkg_dep_version(dep)), "version", 7, false);
		map = ucl_object_insert_key(map, submap, pkg_dep_name(dep), 0, false);
	}
-
	top = ucl_object_insert_key(top, map, "deps", 4, false);
+
	if (map)
+
		top = ucl_object_insert_key(top, map, "deps", 4, false);

	pkg_debug(4, "Emitting categories");
	if (pkg->categories != NULL)
@@ -916,25 +927,29 @@ emit_manifest(struct pkg *pkg, struct sbuf **out, short flags)
	seq = NULL;
	while (pkg_users(pkg, &user) == EPKG_OK)
		seq = ucl_array_append(seq, ucl_object_fromstring(pkg_user_name(user)));
-
	top = ucl_object_insert_key(top, seq, "users", 5, false);
+
	if (seq)
+
		top = ucl_object_insert_key(top, seq, "users", 5, false);

	pkg_debug(4, "Emitting groups");
	seq = NULL;
	while (pkg_groups(pkg, &group) == EPKG_OK) 
		seq = ucl_array_append(seq, ucl_object_fromstring(pkg_group_name(group)));
-
	top = ucl_object_insert_key(top, seq, "groups", 6, false);
+
	if (seq)
+
		top = ucl_object_insert_key(top, seq, "groups", 6, false);

	pkg_debug(4, "Emitting required");
	seq = NULL;
	while (pkg_shlibs_required(pkg, &shlib) == EPKG_OK)
		seq = ucl_array_append(seq, ucl_object_fromstring(pkg_shlib_name(shlib)));
-
	top = ucl_object_insert_key(top, seq, "shlibs_required", 15, false);
+
	if (seq)
+
		top = ucl_object_insert_key(top, seq, "shlibs_required", 15, false);

	pkg_debug(4, "Emitting shlibs_provided");
	seq = NULL;
	while (pkg_shlibs_provided(pkg, &shlib) == EPKG_OK)
		seq = ucl_array_append(seq, ucl_object_fromstring(pkg_shlib_name(shlib)));
-
	top = ucl_object_insert_key(top, seq, "shlibs_provided", 15, false);
+
	if (seq)
+
		top = ucl_object_insert_key(top, seq, "shlibs_provided", 15, false);

	pkg_debug(4, "Emitting conflicts");
	map = NULL;
@@ -942,7 +957,8 @@ emit_manifest(struct pkg *pkg, struct sbuf **out, short flags)
		map = ucl_object_insert_key(map,
		    ucl_object_fromstring(pkg_option_value(option)),
		    pkg_conflict_origin(conflict), 0, false);
-
	top = ucl_object_insert_key(top, map, "conflicts", 9, false);
+
	if (map)
+
		top = ucl_object_insert_key(top, map, "conflicts", 9, false);

	pkg_debug(4, "Emitting provides");
	map = NULL;
@@ -950,7 +966,8 @@ emit_manifest(struct pkg *pkg, struct sbuf **out, short flags)
		map = ucl_object_insert_key(map,
		    ucl_object_fromstring(pkg_option_value(option)),
		    pkg_provide_name(provide), 0, false);
-
	top = ucl_object_insert_key(top, map, "provides", 8, false);
+
	if (map)
+
		top = ucl_object_insert_key(top, map, "provides", 8, false);

	pkg_debug(4, "Emitting options");
	map = NULL;
@@ -960,7 +977,8 @@ emit_manifest(struct pkg *pkg, struct sbuf **out, short flags)
		    ucl_object_fromstring(pkg_option_value(option)),
		    pkg_option_opt(option), 0, false);
	}
-
	top = ucl_object_insert_key(top, map, "options", 7, false);
+
	if (map)
+
		top = ucl_object_insert_key(top, map, "options", 7, false);

	if (pkg->annotations != NULL) {
		/* Remove internal only annotations */
@@ -985,7 +1003,8 @@ emit_manifest(struct pkg *pkg, struct sbuf **out, short flags)
				    ucl_object_fromstring(pkg_sum),
				    sbuf_data(tmpsbuf), sbuf_len(tmpsbuf), true);
			}
-
			top = ucl_object_insert_key(top, map, "files", 5, false);
+
			if (map)
+
				top = ucl_object_insert_key(top, map, "files", 5, false);

			pkg_debug(4, "Emitting directories");
			map = NULL;
@@ -998,7 +1017,8 @@ emit_manifest(struct pkg *pkg, struct sbuf **out, short flags)
				    ucl_object_fromstring(pkg_dir_try(dir) ? "y" : "n"),
				    sbuf_data(tmpsbuf), sbuf_len(tmpsbuf), true);
			}
-
			top = ucl_object_insert_key(top, map, "directories", 11, false);
+
			if (map)
+
				top = ucl_object_insert_key(top, map, "directories", 11, false);
		}

		pkg_debug(4, "Emitting scripts");
@@ -1042,7 +1062,8 @@ emit_manifest(struct pkg *pkg, struct sbuf **out, short flags)
			        sbuf_len(tmpsbuf), UCL_STRING_TRIM),
			    script_types, 0, true);
		}
-
		top = ucl_object_insert_key(top, map, "scripts", 7, false);
+
		if (map)
+
			top = ucl_object_insert_key(top, map, "scripts", 7, false);
	}

	pkg_debug(4, "Emitting message");