Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add compact manifest to a package.
Vsevolod Stakhov committed 13 years ago
commit 1e73231b06909736c30b82de725dee97d5e90d77
parent 14234d4
8 files changed +71 -30
modified libpkg/pkg.c
@@ -1107,7 +1107,20 @@ pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae,
		if (fpath[0] != '+')
			break;

-
		if (strcmp(fpath, "+MANIFEST") == 0) {
+
		if (!manifest &&
+
			(flags & PKG_OPEN_MANIFEST_COMPACT) &&
+
			strcmp(fpath, "+COMPACT_MANIFEST") == 0) {
+
			manifest = true;
+

+
			ret = pkg_parse_manifest_archive(pkg, *a, keys);
+
			if (ret != EPKG_OK) {
+
				retcode = EPKG_FATAL;
+
				goto cleanup;
+
			}
+
			/* Do not read anything more */
+
			break;
+
		}
+
		if (!manifest && strcmp(fpath, "+MANIFEST") == 0) {
			manifest = true;

			ret = pkg_parse_manifest_archive(pkg, *a, keys);
@@ -1157,7 +1170,7 @@ pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae,

	if (!manifest) {
		retcode = EPKG_FATAL;
-
		pkg_emit_error("%s is not a valid package: no +MANIFEST found", path);
+
		pkg_emit_error("%s is not a valid package: no manifest found", path);
	}

	cleanup:
modified libpkg/pkg.h.in
@@ -451,6 +451,7 @@ typedef enum {
} pkg_error_t;

#define PKG_OPEN_MANIFEST_ONLY 0x1
+
#define PKG_OPEN_MANIFEST_COMPACT (0x1 << 1)

/**
 * test if pkg is installed and activated.
@@ -884,12 +885,13 @@ int pkg_is_installed(struct pkgdb *db, const char *origin);
 * Create a repository database.
 * @param path The path where the repository live.
 * @param force If true, rebuild the repository catalogue from scratch
+
 * @param filesite If true, create a list of all files in repo
 * @param callback A function which is called at every step of the process.
 * @param data A pointer which is passed to the callback.
 * @param sum An 65 long char array to receive the sha256 sum
 */
-
int pkg_create_repo(char *path, bool force, void (*callback)(struct pkg *, void *), void *);
-
int pkg_finish_repo(char *path, pem_password_cb *cb, char *rsa_key_path);
+
int pkg_create_repo(char *path, bool force, bool filelist, void (*callback)(struct pkg *, void *), void *);
+
int pkg_finish_repo(char *path, pem_password_cb *cb, char *rsa_key_path, bool filelist);

/**
 * Test if the EUID has sufficient privilege to carry out some
modified libpkg/pkg_create.c
@@ -105,6 +105,9 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,

		pkg_register_shlibs(pkg);

+
		pkg_emit_manifest_sbuf(pkg, b, PKG_MANIFEST_EMIT_COMPACT, NULL);
+
		packing_append_buffer(pkg_archive, sbuf_data(b), "+COMPACT_MANIFEST", sbuf_len(b));
+
		sbuf_clear(b);
		pkg_emit_manifest_sbuf(pkg, b, 0, NULL);
		sbuf_finish(b);
		packing_append_buffer(pkg_archive, sbuf_data(b), "+MANIFEST", sbuf_len(b));
modified libpkg/pkg_manifest.c
@@ -738,7 +738,7 @@ parse_manifest(struct pkg *pkg, struct pkg_manifest_key *keys, yaml_parser_t *pa
	node = yaml_document_get_root_node(&doc);
	if (node != NULL) {
		if (node->type != YAML_MAPPING_NODE) {
-
			pkg_emit_error("Invalid manifest format");
+
			pkg_emit_error("Invalid manifest format in package");
		} else {
			retcode = parse_root_node(pkg, keys, node, &doc);
		}
modified libpkg/pkg_repo.c
@@ -189,7 +189,8 @@ digest_sort_compare_func(struct digest_list_entry *d1, struct digest_list_entry
}

int
-
pkg_create_repo(char *path, bool force, void (progress)(struct pkg *pkg, void *data), void *data)
+
pkg_create_repo(char *path, bool force, bool filelist,
+
		void (progress)(struct pkg *pkg, void *data), void *data)
{
	FTS *fts = NULL;
	struct thd_data thd_data;
@@ -233,10 +234,12 @@ pkg_create_repo(char *path, bool force, void (progress)(struct pkg *pkg, void *d
		retcode = EPKG_FATAL;
		goto cleanup;
	}
-
	snprintf(repodb, sizeof(repodb), "%s/%s", path, repo_filesite_file);
-
	if ((fsyml = fopen(repodb, "w")) == NULL) {
-
		retcode = EPKG_FATAL;
-
		goto cleanup;
+
	if (filelist) {
+
		snprintf(repodb, sizeof(repodb), "%s/%s", path, repo_filesite_file);
+
		if ((fsyml = fopen(repodb, "w")) == NULL) {
+
			retcode = EPKG_FATAL;
+
			goto cleanup;
+
		}
	}
	snprintf(repodb, sizeof(repodb), "%s/%s", path, repo_digests_file);
	if ((mandigests = fopen(repodb, "w")) == NULL) {
@@ -260,6 +263,7 @@ pkg_create_repo(char *path, bool force, void (progress)(struct pkg *pkg, void *d
	thd_data.num_results = 0;
	thd_data.stop = false;
	thd_data.fts = fts;
+
	thd_data.read_files = filelist;
	pthread_mutex_init(&thd_data.fts_m, NULL);
	thd_data.results = NULL;
	thd_data.thd_finished = 0;
@@ -315,9 +319,13 @@ pkg_create_repo(char *path, bool force, void (progress)(struct pkg *pkg, void *d
			progress(r->pkg, data);

		manifest_pos = ftell(psyml);
-
		files_pos = ftell(fsyml);
		pkg_emit_manifest_file(r->pkg, psyml, PKG_MANIFEST_EMIT_COMPACT, &manifest_digest);
-
		pkg_emit_filelist(r->pkg, fsyml);
+
		if (filelist) {
+
			files_pos = ftell(fsyml);
+
			pkg_emit_filelist(r->pkg, fsyml);
+
		} else {
+
			files_pos = 0;
+
		}

		pkg_get(r->pkg, PKG_ORIGIN, &origin);

@@ -405,7 +413,7 @@ read_pkg_file(void *data)
	char fts_path[MAXPATHLEN + 1];
	char fts_name[MAXPATHLEN + 1];
	off_t st_size;
-
	int fts_info;
+
	int fts_info, flags;

	char *ext = NULL;
	char *pkg_path;
@@ -467,7 +475,12 @@ read_pkg_file(void *data)

		r = calloc(1, sizeof(struct pkg_result));

-
		if (pkg_open(&r->pkg, fts_accpath, keys, PKG_OPEN_MANIFEST_ONLY) != EPKG_OK) {
+
		if (d->read_files)
+
			flags = PKG_OPEN_MANIFEST_ONLY;
+
		else
+
			flags = PKG_OPEN_MANIFEST_ONLY | PKG_OPEN_MANIFEST_COMPACT;
+

+
		if (pkg_open(&r->pkg, fts_accpath, keys, flags) != EPKG_OK) {
			r->retcode = EPKG_WARN;
		} else {
			sha256_file(fts_accpath, r->cksum);
@@ -532,7 +545,7 @@ pack_db(const char *name, const char *archive, char *path,
}

int
-
pkg_finish_repo(char *path, pem_password_cb *password_cb, char *rsa_key_path)
+
pkg_finish_repo(char *path, pem_password_cb *password_cb, char *rsa_key_path, bool filelist)
{
	char repo_path[MAXPATHLEN + 1];
	char repo_archive[MAXPATHLEN + 1];
@@ -555,11 +568,13 @@ pkg_finish_repo(char *path, pem_password_cb *password_cb, char *rsa_key_path)
			rsa_key_path, password_cb) != EPKG_OK)
		return (EPKG_FATAL);

-
	snprintf(repo_path, sizeof(repo_path), "%s/%s", path, repo_filesite_file);
-
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", path, repo_filesite_archive);
-
	if (pack_db(repo_filesite_file, repo_archive, repo_path,
-
			rsa_key_path, password_cb) != EPKG_OK)
-
		return (EPKG_FATAL);
+
	if (filelist) {
+
		snprintf(repo_path, sizeof(repo_path), "%s/%s", path, repo_filesite_file);
+
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s", path, repo_filesite_archive);
+
		if (pack_db(repo_filesite_file, repo_archive, repo_path,
+
				rsa_key_path, password_cb) != EPKG_OK)
+
			return (EPKG_FATAL);
+
	}

	snprintf(repo_path, sizeof(repo_path), "%s/%s", path, repo_digests_file);
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", path, repo_digests_archive);
@@ -584,8 +599,10 @@ pkg_finish_repo(char *path, pem_password_cb *password_cb, char *rsa_key_path)
		utimes(repo_archive, ftimes);
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz", path, repo_digests_archive);
		utimes(repo_archive, ftimes);
-
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz", path, repo_filesite_archive);
-
		utimes(repo_archive, ftimes);
+
		if (filelist) {
+
			snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz", path, repo_filesite_archive);
+
			utimes(repo_archive, ftimes);
+
		}
	}

	return (EPKG_OK);
modified libpkg/private/thd_repo.h
@@ -49,6 +49,7 @@ struct thd_data {
	pthread_mutex_t fts_m;
	FTS *fts;
	bool stop;
+
	bool read_files;

	/*
	 * `results_m' protects `results', `thd_finished' and `num_results'
modified pkg/pkg-repo.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd April 13, 2013
+
.Dd April 15, 2013
.Dt PKG-REPO 8
.Os
.Sh NAME
@@ -23,7 +23,7 @@
.Nd creates a package repository catalogue
.Sh SYNOPSIS
.Nm
-
.Op Fl fq
+
.Op Fl flq
.Ao Ar repo-path Ac Op Ar rsa-key
.Sh DESCRIPTION
.Nm
@@ -69,6 +69,8 @@ Force quiet output
.It Fl f
Force a full rebuild of the package catalogue, discarding any previous
content
+
.It Fl l
+
Generate list of all files in repo as filesite.txz archive.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
modified pkg/repo.c
@@ -37,7 +37,7 @@
void
usage_repo(void)
{
-
	fprintf(stderr, "usage: pkg repo [-fq] <repo-path> <rsa-key>\n\n");
+
	fprintf(stderr, "usage: pkg repo [-flq] <repo-path> <rsa-key>\n\n");
	fprintf(stderr, "For more information see 'pkg help repo'.\n");
}

@@ -89,9 +89,9 @@ exec_repo(int argc, char **argv)
	int pos = 0;
	int ch;
	char *rsa_key;
-
	bool force = false;
+
	bool force = false, filelist = false;

-
	while ((ch = getopt(argc, argv, "fq")) != -1) {
+
	while ((ch = getopt(argc, argv, "flq")) != -1) {
		switch (ch) {
		case 'q':
			quiet = true;
@@ -99,6 +99,9 @@ exec_repo(int argc, char **argv)
		case 'f':
			force = true;
			break;
+
		case 'l':
+
			filelist = true;
+
			break;
		default:
			usage_repo();
			return (EX_USAGE);
@@ -114,9 +117,9 @@ exec_repo(int argc, char **argv)

	if (!quiet) {
		printf("Generating repository catalog in %s:  ", argv[0]);
-
		ret = pkg_create_repo(argv[0], force, progress, &pos);
+
		ret = pkg_create_repo(argv[0], force, filelist, progress, &pos);
	} else
-
		ret = pkg_create_repo(argv[0], force, NULL, NULL);
+
		ret = pkg_create_repo(argv[0], force, filelist, NULL, NULL);

	if (ret != EPKG_OK) {
		printf("cannot create repository catalogue\n");
@@ -127,7 +130,7 @@ exec_repo(int argc, char **argv)
	}
	
	rsa_key = (argc == 2) ? argv[1] : NULL;
-
	pkg_finish_repo(argv[0], password_cb, rsa_key);
+
	pkg_finish_repo(argv[0], password_cb, rsa_key, filelist);

	return (EX_OK);
}