Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add repo meta export function.
Vsevolod Stakhov committed 11 years ago
commit a05ee8f31a2a3a1606f2308a6328d1f68dfeec90
parent c2a6a3c
5 files changed +59 -2
modified libpkg/pkg.h.in
@@ -958,8 +958,10 @@ int pkg_is_installed(struct pkgdb *db, const char *origin);
 * @param output_dir The path where the package repository should be created.
 * @param force If true, rebuild the repository catalogue from scratch
 * @param filesite If true, create a list of all files in repo
+
 * @param metafile Open meta from the specified file
 */
-
int pkg_create_repo(char *path, const char *output_dir, bool filelist);
+
int pkg_create_repo(char *path, const char *output_dir, bool filelist,
+
	const char *metafile);
int pkg_finish_repo(const char *output_dir, pem_password_cb *cb, char **argv,
    int argc, bool filelist);

modified libpkg/pkg_checksum.c
@@ -356,6 +356,12 @@ pkg_checksum_type_from_string(const char *name)
	return (PKG_HASH_TYPE_UNKNOWN);
}

+
const char*
+
pkg_checksum_type_to_string(pkg_checksum_type_t type)
+
{
+
	return (checksum_types[type].name);
+
}
+

size_t
pkg_checksum_type_size(pkg_checksum_type_t type)
{
modified libpkg/pkg_repo_create.c
@@ -472,7 +472,8 @@ pkg_create_repo_read_pipe(int fd, struct digest_list_entry **dlist)
}

int
-
pkg_create_repo(char *path, const char *output_dir, bool filelist)
+
pkg_create_repo(char *path, const char *output_dir, bool filelist,
+
	const char *metafile)
{
	FTS *fts = NULL;
	struct pkg_fts_item *fts_items = NULL, *fts_cur;
modified libpkg/pkg_repo_meta.c
@@ -170,6 +170,7 @@ pkg_repo_meta_parse(ucl_object_t *top, struct pkg_repo_meta **target, int versio
	}

	pkg_repo_meta_set_default(meta);
+
	meta->version = version;

	META_EXTRACT_STRING(maintainer);
	META_EXTRACT_STRING(source);
@@ -290,3 +291,47 @@ pkg_repo_meta_default(void)

	return (meta);
}
+

+
#define META_EXPORT_FIELD(result, meta, field, type)	do { 					\
+
	if (strcmp(#type, "string") != 0 || meta->field != 0)					\
+
		ucl_object_insert_key((result), ucl_object_from ## type (meta->field),	\
+
				#field, 0, false); 												\
+
	} while(0)
+

+
#define META_EXPORT_FIELD_FUNC(result, meta, field, type, func)	do {			\
+
	if (strcmp(#type, "string") != 0 || func(meta->field) != 0)				\
+
		ucl_object_insert_key((result), ucl_object_from ## type (func(meta->field)), \
+
				#field, 0, false); 												\
+
	} while(0)
+

+

+
ucl_object_t *
+
pkg_repo_meta_to_ucl(struct pkg_repo_meta *meta)
+
{
+
	ucl_object_t *result = ucl_object_typed_new(UCL_OBJECT);
+

+
	META_EXPORT_FIELD(result, meta, version, int);
+
	META_EXPORT_FIELD(result, meta, maintainer, string);
+
	META_EXPORT_FIELD(result, meta, source, string);
+

+
	META_EXPORT_FIELD_FUNC(result, meta, packing_format, string,
+
		packing_format_to_string);
+
	META_EXPORT_FIELD_FUNC(result, meta, digest_format, string,
+
		pkg_checksum_type_to_string);
+

+
	META_EXPORT_FIELD(result, meta, digests, string);
+
	META_EXPORT_FIELD(result, meta, manifests, string);
+
	META_EXPORT_FIELD(result, meta, conflicts, string);
+
	META_EXPORT_FIELD(result, meta, fulldb, string);
+

+
	META_EXPORT_FIELD(result, meta, source_identifier, string);
+
	META_EXPORT_FIELD(result, meta, revision, int);
+
	META_EXPORT_FIELD(result, meta, eol, int);
+

+
	/* TODO: export keys */
+

+
	return (result);
+
}
+

+
#undef META_EXPORT_FIELD
+
#undef META_EXPORT_FIELD_FUNC
modified libpkg/private/pkg.h
@@ -322,6 +322,8 @@ struct pkg_repo_meta {
	struct pkg_repo_meta_key *keys;

	time_t eol;
+

+
	int version;
};

struct pkg_repo_it_ops {
@@ -606,6 +608,7 @@ int pkg_checksum_generate(struct pkg *pkg, char *dest, size_t destlen,
bool pkg_checksum_is_valid(const char *cksum, size_t clen);
pkg_checksum_type_t pkg_checksum_get_type(const char *cksum, size_t clen);
pkg_checksum_type_t pkg_checksum_type_from_string(const char *name);
+
const char* pkg_checksum_type_to_string(pkg_checksum_type_t type);
size_t pkg_checksum_type_size(pkg_checksum_type_t type);
int pkg_checksum_calculate(struct pkg *pkg, struct pkgdb *db);