Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
manifest: sort lists to make them reproducible
Baptiste Daroussin committed 1 year ago
commit fc571f97aeee4dcf48a5a6be937f34b75d58a6c7
parent 674dd2a
3 files changed +41 -0
modified libpkg/pkg.c
@@ -1725,3 +1725,42 @@ pkg_message_to_str(struct pkg *pkg)

	return (ret);
}
+

+
static int
+
pkg_dep_cmp(struct pkg_dep *a, struct pkg_dep *b)
+
{
+
	return (STREQ(a->name, b->name));
+
}
+

+
static int
+
pkg_file_cmp(struct pkg_file *a, struct pkg_file *b)
+
{
+
	return (STREQ(a->path, b->path));
+
}
+

+
static int
+
pkg_dir_cmp(struct pkg_dir *a, struct pkg_dir *b)
+
{
+
	return (STREQ(a->path, b->path));
+
}
+

+
static int
+
pkg_option_cmp(struct pkg_option *a, struct pkg_option *b)
+
{
+
	return (STREQ(a->key, b->key));
+
}
+

+
static int
+
pkg_cf_cmp(struct pkg_config_file *a, struct pkg_config_file *b)
+
{
+
	return (STREQ(a->path, b->path));
+
}
+
void
+
pkg_lists_sort(struct pkg *p)
+
{
+
	DL_SORT(p->depends, pkg_dep_cmp);
+
	DL_SORT(p->files, pkg_file_cmp);
+
	DL_SORT(p->dirs, pkg_dir_cmp);
+
	DL_SORT(p->options, pkg_option_cmp);
+
	DL_SORT(p->config_files, pkg_cf_cmp);
+
}
modified libpkg/pkg_manifest.c
@@ -955,6 +955,7 @@ pkg_emit_object(struct pkg *pkg, short flags)
	pkg_arch_to_legacy(pkg->abi, legacyarch, BUFSIZ);
	free(pkg->altabi);
	pkg->altabi = xstrdup(legacyarch);
+
	pkg_lists_sort(pkg);
	dbg(4, "Emitting basic metadata");
	MANIFEST_EXPORT_FIELD(top, pkg, name, string);
	MANIFEST_EXPORT_FIELD(top, pkg, origin, string);
modified libpkg/private/pkg.h
@@ -861,5 +861,6 @@ int pkg_get_reposdirfd(void);
char * expand_plist_variables(const char *in, kvlist_t *vars);

int scan_system_shlibs(pkghash **system_shlibs, const char *rootdir);
+
void pkg_lists_sort(struct pkg *p);

#endif