Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkg-repo: Add a -o output_dir option
Bryan Drewery committed 12 years ago
commit 0d2286b63c7cb46aca5ddd1464ec43fbceb48224
parent e4dbdd9
3 files changed +57 -23
modified libpkg/pkg_repo.c
@@ -153,7 +153,7 @@ digest_sort_compare_func(struct digest_list_entry *d1, struct digest_list_entry
}

int
-
pkg_create_repo(char *path, bool filelist,
+
pkg_create_repo(char *path, const char *output_dir, bool filelist,
		void (progress)(struct pkg *pkg, void *data), void *data)
{
	FTS *fts = NULL;
@@ -177,6 +177,11 @@ pkg_create_repo(char *path, bool filelist,
		return (EPKG_FATAL);
	}

+
	if (!is_dir(output_dir)) {
+
		pkg_emit_error("%s is not a directory", output_dir);
+
		return (EPKG_FATAL);
+
	}
+

	repopath[0] = path;
	repopath[1] = NULL;

@@ -190,19 +195,22 @@ pkg_create_repo(char *path, bool filelist,
		goto cleanup;
	}

-
	snprintf(repodb, sizeof(repodb), "%s/%s", path, repo_packagesite_file);
+
	snprintf(repodb, sizeof(repodb), "%s/%s", output_dir,
+
	    repo_packagesite_file);
	if ((psyml = fopen(repodb, "w")) == NULL) {
		retcode = EPKG_FATAL;
		goto cleanup;
	}
	if (filelist) {
-
		snprintf(repodb, sizeof(repodb), "%s/%s", path, repo_filesite_file);
+
		snprintf(repodb, sizeof(repodb), "%s/%s", output_dir,
+
		    repo_filesite_file);
		if ((fsyml = fopen(repodb, "w")) == NULL) {
			retcode = EPKG_FATAL;
			goto cleanup;
		}
	}
-
	snprintf(repodb, sizeof(repodb), "%s/%s", path, repo_digests_file);
+
	snprintf(repodb, sizeof(repodb), "%s/%s", output_dir,
+
	    repo_digests_file);
	if ((mandigests = fopen(repodb, "w")) == NULL) {
		retcode = EPKG_FATAL;
		goto cleanup;
@@ -568,7 +576,8 @@ pack_db(const char *name, const char *archive, char *path, struct rsa_key *rsa,
}

int
-
pkg_finish_repo(char *path, pem_password_cb *password_cb, char **argv, int argc, bool filelist)
+
pkg_finish_repo(const char *output_dir, pem_password_cb *password_cb,
+
    char **argv, int argc, bool filelist)
{
	char repo_path[MAXPATHLEN + 1];
	char repo_archive[MAXPATHLEN + 1];
@@ -576,9 +585,9 @@ pkg_finish_repo(char *path, pem_password_cb *password_cb, char **argv, int argc,
	struct stat st;
	int ret = EPKG_OK;
	
-
	if (!is_dir(path)) {
-
	    pkg_emit_error("%s is not a directory", path);
-
	    return (EPKG_FATAL);
+
	if (!is_dir(output_dir)) {
+
		pkg_emit_error("%s is not a directory", output_dir);
+
		return (EPKG_FATAL);
	}

	if (argc == 1) {
@@ -593,31 +602,38 @@ pkg_finish_repo(char *path, pem_password_cb *password_cb, char **argv, int argc,
		argv++;
	}

-
	snprintf(repo_path, sizeof(repo_path), "%s/%s", path, repo_packagesite_file);
-
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", path, repo_packagesite_archive);
+
	snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
+
	    repo_packagesite_file);
+
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", output_dir,
+
	    repo_packagesite_archive);
	if (pack_db(repo_packagesite_file, repo_archive, repo_path, rsa, argv, argc) != EPKG_OK) {
		ret = EPKG_FATAL;
		goto cleanup;
	}

	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);
+
		snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
+
		    repo_filesite_file);
+
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s",
+
		    output_dir, repo_filesite_archive);
		if (pack_db(repo_filesite_file, repo_archive, repo_path, rsa, argv, argc) != EPKG_OK) {
			ret = EPKG_FATAL;
			goto cleanup;
		}
	}

-
	snprintf(repo_path, sizeof(repo_path), "%s/%s", path, repo_digests_file);
-
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", path, repo_digests_archive);
+
	snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
+
	    repo_digests_file);
+
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", output_dir,
+
	    repo_digests_archive);
	if (pack_db(repo_digests_file, repo_archive, repo_path, rsa, argv, argc) != EPKG_OK) {
		ret = EPKG_FATAL;
		goto cleanup;
	}

	/* Now we need to set the equal mtime for all archives in the repo */
-
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz", path, repo_db_archive);
+
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz",
+
	    output_dir, repo_db_archive);
	if (stat(repo_archive, &st) == 0) {
		struct timeval ftimes[2] = {
			{
@@ -629,12 +645,15 @@ pkg_finish_repo(char *path, pem_password_cb *password_cb, char **argv, int argc,
			.tv_usec = 0
			}
		};
-
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz", path, repo_packagesite_archive);
+
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz",
+
		    output_dir, repo_packagesite_archive);
		utimes(repo_archive, ftimes);
-
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz", path, repo_digests_archive);
+
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz",
+
		    output_dir, repo_digests_archive);
		utimes(repo_archive, ftimes);
		if (filelist) {
-
			snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz", path, repo_filesite_archive);
+
			snprintf(repo_archive, sizeof(repo_archive),
+
			    "%s/%s.txz", output_dir, repo_filesite_archive);
			utimes(repo_archive, ftimes);
		}
	}
modified pkg/pkg-repo.8
@@ -24,6 +24,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl flq
+
.Op Fl o Ar output-dir
.Ao Ar repo-path Ac Op Ao Ar rsa-key Ac | signing_command: Ao Ar the command Ac
.Sh DESCRIPTION
.Nm
@@ -55,6 +56,10 @@ If a catalogue already exists, it will be updated incrementally with
any changes to the package collection.
This is a significant time savings for large package repositories.
.Pp
+
The repository will be created in the package directory unless the
+
.Fl o Ar output-dir
+
is specified, in which case it will be created there.
+
.Pp
Optionally you may sign the repository catalogue by specifying the
path to an RSA private key as the
.Ar rsa-key
@@ -96,6 +101,8 @@ 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.
+
.It Fl o Ar output-dir
+
Create the repository in the specified directory instead of the package directory.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
modified pkg/repo.c
@@ -37,7 +37,8 @@
void
usage_repo(void)
{
-
	fprintf(stderr, "Usage: pkg repo [-lq] <repo-path> [<rsa-key>|signing_command: <the command>]\n\n");
+
	fprintf(stderr, "Usage: pkg repo [-lq] [-o output-dir] <repo-path> "
+
	    "[<rsa-key>|signing_command: <the command>]\n\n");
	fprintf(stderr, "For more information see 'pkg help repo'.\n");
}

@@ -89,8 +90,9 @@ exec_repo(int argc, char **argv)
	int pos = 0;
	int ch;
	bool filelist = false;
+
	char *output_dir = NULL;

-
	while ((ch = getopt(argc, argv, "lq")) != -1) {
+
	while ((ch = getopt(argc, argv, "lo:q")) != -1) {
		switch (ch) {
		case 'q':
			quiet = true;
@@ -98,6 +100,9 @@ exec_repo(int argc, char **argv)
		case 'l':
			filelist = true;
			break;
+
		case 'o':
+
			output_dir = optarg;
+
			break;
		default:
			usage_repo();
			return (EX_USAGE);
@@ -116,11 +121,14 @@ exec_repo(int argc, char **argv)
		return (EX_USAGE);
	}

+
	if (output_dir == NULL)
+
		output_dir = argv[0];
+

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

	if (ret != EPKG_OK) {
		printf("Cannot create repository catalogue\n");
@@ -130,7 +138,7 @@ exec_repo(int argc, char **argv)
			printf("\bdone!\n");
	}
	
-
	if (pkg_finish_repo(argv[0], password_cb, argv + 1, argc - 1,
+
	if (pkg_finish_repo(output_dir, password_cb, argv + 1, argc - 1,
	    filelist) != EPKG_OK)
		return (EX_DATAERR);