Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add a '-R' option to specify the directory to search for per-repository configuration files. This overrides the REPOS_DIR value set in pkg.conf(5).
Matthew Seaman committed 12 years ago
commit dd5cff4c55047d119faf8b6e076f24abc3d0a940
parent 14de7d3
4 files changed +33 -20
modified libpkg/pkg.h.in
@@ -1371,7 +1371,7 @@ typedef int(*pkg_event_cb)(void *, struct pkg_event *);

void pkg_event_register(pkg_event_cb cb, void *data);

-
int pkg_init(const char *);
+
int pkg_init(const char *, const char *);
int pkg_initialized(void);
void pkg_shutdown(void);

modified libpkg/pkg_config.c
@@ -882,10 +882,10 @@ load_repo_files(const char *repodir)
}

static void
-
load_repositories(void)
+
load_repositories(const char *repodir)
{
	struct pkg_repo *r;
-
	const char *url, *pub, *repodir, *mirror_type;
+
	const char *url, *pub, *mirror_type;

	pkg_config_string(PKG_CONFIG_REPO, &url);
	pkg_config_string(PKG_CONFIG_REPOKEY, &pub);
@@ -908,13 +908,14 @@ load_repositories(void)
		HASH_ADD_KEYPTR(hh, repos, r->name, strlen(r->name), r);
	}

-
	pkg_config_string(PKG_CONFIG_REPOS_DIR, &repodir);
+
	if (repodir == NULL)
+
		pkg_config_string(PKG_CONFIG_REPOS_DIR, &repodir);
	if (repodir != NULL)
		load_repo_files(repodir);
}

int
-
pkg_init(const char *path)
+
pkg_init(const char *path, const char *reposdir)
{
	FILE *fp;
	yaml_parser_t parser;
@@ -1112,7 +1113,7 @@ pkg_init(const char *path)
	}

	/* load the repositories */
-
	load_repositories();
+
	load_repositories(reposdir);

	setenv("HTTP_USER_AGENT", "pkg/"PKGVERSION, 1);

modified pkg/main.c
@@ -53,7 +53,7 @@
#define GITHASH ""
#endif

-
static void usage(const char *);
+
static void usage(const char *, const char *);
static void usage_help(void);
static int exec_help(int, char **);
bool quiet = false;
@@ -126,15 +126,15 @@ show_command_names(void)
}

static void
-
usage(const char *conffile)
+
usage(const char *conffile, const char *reposdir)
{
	struct plugcmd *c;
	bool plugins_enabled = false;

#ifndef NO_LIBJAIL
-
 	fprintf(stderr, "usage: pkg [-v] [-d] [-l] [-N] [-j <jail name or id>|-c <chroot path>] [-C <configuration file>] <command> [<args>]\n\n");
+
 	fprintf(stderr, "usage: pkg [-v] [-d] [-l] [-N] [-j <jail name or id>|-c <chroot path>] [-C <configuration file>] [-R <repo config dir>] <command> [<args>]\n\n");
#else
-
	fprintf(stderr, "usage: pkg [-v] [-d] [-l] [-N] [-c <chroot path>] [-C <configuration file>] <command> [<args>]\n\n");
+
	fprintf(stderr, "usage: pkg [-v] [-d] [-l] [-N] [-c <chroot path>] [-C <configuration file>] [-R <repo config dir>] <command> [<args>]\n\n");
#endif
	fprintf(stderr, "Global options supported:\n");
	fprintf(stderr, "\t%-15s%s\n", "-d", "Increment debug level");
@@ -143,6 +143,7 @@ usage(const char *conffile)
#endif
	fprintf(stderr, "\t%-15s%s\n", "-c", "Execute pkg(1) inside a chroot(8)");
	fprintf(stderr, "\t%-15s%s\n", "-C", "Use the specified configuration file");
+
	fprintf(stderr, "\t%-15s%s\n", "-R", "Directory to search for individual repository configurations");
	fprintf(stderr, "\t%-15s%s\n", "-l", "List available command and exit");
	fprintf(stderr, "\t%-15s%s\n", "-v", "Display pkg(1) version");
	fprintf(stderr, "\t%-15s%s\n\n", "-N", "Test if pkg(1) is activated and avoid auto-activation");
@@ -151,7 +152,7 @@ usage(const char *conffile)
	for (unsigned int i = 0; i < cmd_len; i++)
		fprintf(stderr, "\t%-15s%s\n", cmd[i].name, cmd[i].desc);

-
	if (!pkg_initialized() && pkg_init(conffile) != EPKG_OK)
+
	if (!pkg_initialized() && pkg_init(conffile, reposdir) != EPKG_OK)
		errx(EX_SOFTWARE, "Cannot parse configuration file!");

	pkg_config_bool(PKG_CONFIG_ENABLE_PLUGINS, &plugins_enabled);
@@ -175,7 +176,7 @@ usage(const char *conffile)
static void
usage_help(void)
{
-
	usage(NULL);
+
	usage(NULL, NULL);
}

static int
@@ -507,6 +508,7 @@ main(int argc, char **argv)
	bool activation_test = false;
	struct plugcmd *c;
	const char *conffile = NULL;
+
	const char *reposdir = NULL;
	struct pkg_config_kv *alias = NULL;
	const char *alias_value, *errmsg;
	char **newargv;
@@ -517,14 +519,14 @@ main(int argc, char **argv)
	setvbuf(stdout, NULL, _IONBF, 0);

	if (argc < 2)
-
		usage(NULL);
+
		usage(NULL, NULL);

	cmdargv = argv;

#ifndef NO_LIBJAIL
-
	while ((ch = getopt(argc, argv, "dj:c:C:lNvq")) != -1) {
+
	while ((ch = getopt(argc, argv, "dj:c:C:R:lNvq")) != -1) {
#else
-
	while ((ch = getopt(argc, argv, "d:c:C:lNvq")) != -1) {
+
	while ((ch = getopt(argc, argv, "d:c:C:R:lNvq")) != -1) {
#endif
		switch (ch) {
		case 'd':
@@ -536,6 +538,9 @@ main(int argc, char **argv)
		case 'C':
			conffile = optarg;
			break;
+
		case 'R':
+
			reposdir = optarg;
+
			break;
#ifndef NO_LIBJAIL
		case 'j':
			jail_str = optarg;
@@ -565,7 +570,7 @@ main(int argc, char **argv)
		exit(EX_OK);
	}
	if (argc == 0 && version == 0 && !activation_test)
-
		usage(conffile);
+
		usage(conffile, reposdir);

	umask(022);
	pkg_event_register(&event_callback, &debug);
@@ -576,7 +581,7 @@ main(int argc, char **argv)

	if (jail_str != NULL && chroot_path != NULL) {
		fprintf(stderr, "-j and -c cannot be used at the same time!\n");
-
		usage(conffile);
+
		usage(conffile, reposdir);
	}

	if (chroot_path != NULL)
@@ -598,7 +603,7 @@ main(int argc, char **argv)
			errx(EX_SOFTWARE, "chdir() failed");
#endif

-
	if (pkg_init(conffile) != EPKG_OK)
+
	if (pkg_init(conffile, reposdir) != EPKG_OK)
		errx(EX_SOFTWARE, "Cannot parse configuration file!");

	if (atexit(&pkg_shutdown) != 0)
@@ -688,7 +693,7 @@ main(int argc, char **argv)
		}

		if (!plugin_found)
-
			usage(conffile);
+
			usage(conffile, reposdir);

		return (ret);
	}
modified pkg/pkg.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd June 11, 2013
+
.Dd September 8, 2013
.Dt PKG 8
.Os
.\" ---------------------------------------------------------------------------
@@ -32,6 +32,7 @@
.Op Fl N
.Op Fl j Ao jail name or id Ac | Fl c Ao chroot path Ac
.Op Fl C Ao configuration file Ac
+
.Op Fl R Ao repository configuration directory Ac
.Ao command Ac Ao Ar flags Ac
.\" ---------------------------------------------------------------------------
.Sh DESCRIPTION
@@ -152,6 +153,12 @@ Environment
.It Fl C Ao configuration file Ac
.Nm
will use the specified file as a configuration file
+
.It Fl R Ao repository configuration directory Ac
+
.Nm
+
will search the directory for per-repository configuration files.
+
This overrides any value of
+
.Ev REPOS_DIR
+
specified in the main configuration file.
.El
.\" ---------------------------------------------------------------------------
.Sh COMMANDS