[pacman-dev] [PATCH v3 05/11] pacman: add user hook directories

Andrew Gregory andrew.gregory.8 at gmail.com
Sat Oct 17 00:28:27 UTC 2015


---
 doc/pacman.conf.5.txt  |  8 ++++++++
 src/pacman/Makefile.am |  2 ++
 src/pacman/conf.c      | 22 ++++++++++++++++++++++
 src/pacman/conf.h      |  2 ++
 src/pacman/pacman.c    | 10 ++++++++++
 5 files changed, 44 insertions(+)

diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt
index 383e072..b78d1fe 100644
--- a/doc/pacman.conf.5.txt
+++ b/doc/pacman.conf.5.txt
@@ -70,6 +70,14 @@ Options
 	to the first cache directory with write access. *NOTE*: this is an absolute
 	path, the root path is not automatically prepended.
 
+*HookDir =* path/to/hook/dir::
+	Add directories to search for alpm hooks.  A typical default is
+	+{sysconfdir}/pacman.d/hooks+.  Multiple directories can be specified with
+	hooks in later directories taking precedence over hooks in earlier
+	directories.  *NOTE*: this is an absolute path, the root path is not
+	automatically prepended.  For more information on the alpm hooks, see
+	linkman:alpm-hooks[5].
+
 *GPGDir =* path/to/gpg/dir::
 	Overrides the default location of the directory containing configuration
 	files for GnuPG. A typical default is +{sysconfdir}/pacman.d/gnupg/+.
diff --git a/src/pacman/Makefile.am b/src/pacman/Makefile.am
index d3ae071..b07c670 100644
--- a/src/pacman/Makefile.am
+++ b/src/pacman/Makefile.am
@@ -4,6 +4,7 @@ SUBDIRS = po
 conffile  = ${sysconfdir}/pacman.conf
 dbpath    = ${localstatedir}/lib/pacman/
 gpgdir    = ${sysconfdir}/pacman.d/gnupg/
+hookdir   = ${sysconfdir}/pacman.d/hooks/
 cachedir  = ${localstatedir}/cache/pacman/pkg/
 logfile   = ${localstatedir}/log/pacman.log
 
@@ -16,6 +17,7 @@ AM_CPPFLAGS = \
 	-DCONFFILE=\"$(conffile)\" \
 	-DDBPATH=\"$(dbpath)\" \
 	-DGPGDIR=\"$(gpgdir)\" \
+	-DHOOKDIR=\"$(hookdir)\" \
 	-DCACHEDIR=\"$(cachedir)\" \
 	-DLOGFILE=\"$(logfile)\"
 
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 738b026..6a2b206 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -146,6 +146,7 @@ int config_free(config_t *oldconfig)
 	free(oldconfig->dbpath);
 	free(oldconfig->logfile);
 	free(oldconfig->gpgdir);
+	FREELIST(oldconfig->hookdirs);
 	FREELIST(oldconfig->cachedirs);
 	free(oldconfig->xfercommand);
 	free(oldconfig->print_format);
@@ -515,6 +516,8 @@ static int _parse_options(const char *key, char *value,
 			setrepeatingoption(value, "HoldPkg", &(config->holdpkg));
 		} else if(strcmp(key, "CacheDir") == 0) {
 			setrepeatingoption(value, "CacheDir", &(config->cachedirs));
+		} else if(strcmp(key, "HookDir") == 0) {
+			setrepeatingoption(value, "HookDir", &(config->hookdirs));
 		} else if(strcmp(key, "Architecture") == 0) {
 			if(!config->arch) {
 				config_set_arch(value);
@@ -751,6 +754,25 @@ static int setup_libalpm(void)
 		return ret;
 	}
 
+	/* Set user hook directory. This is not relative to rootdir, even if
+	 * rootdir is defined. Reasoning: hookdir contains configuration data. */
+	if(config->hookdirs == NULL) {
+		if((ret = alpm_option_add_hookdir(handle, HOOKDIR)) != 0) {
+			pm_printf(ALPM_LOG_ERROR, _("problem adding hookdir '%s' (%s)\n"),
+					HOOKDIR, alpm_strerror(alpm_errno(handle)));
+			return ret;
+		}
+	} else {
+		/* add hook directories 1-by-1 to avoid overwriting the system directory */
+		for(i = config->hookdirs; i; i = alpm_list_next(i)) {
+			if((ret = alpm_option_add_hookdir(handle, i->data)) != 0) {
+				pm_printf(ALPM_LOG_ERROR, _("problem adding hookdir '%s' (%s)\n"),
+						(char *) i->data, alpm_strerror(alpm_errno(handle)));
+				return ret;
+			}
+		}
+	}
+
 	/* add a default cachedir if one wasn't specified */
 	if(config->cachedirs == NULL) {
 		alpm_option_add_cachedir(handle, CACHEDIR);
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 3fff900..cde6741 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -66,6 +66,7 @@ typedef struct __config_t {
 	char *dbpath;
 	char *logfile;
 	char *gpgdir;
+	alpm_list_t *hookdirs;
 	alpm_list_t *cachedirs;
 
 	unsigned short op_q_isfile;
@@ -156,6 +157,7 @@ enum {
 	OP_NOSCRIPTLET,
 	OP_ASK,
 	OP_CACHEDIR,
+	OP_HOOKDIR,
 	OP_ASDEPS,
 	OP_LOGFILE,
 	OP_IGNOREGROUP,
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index c680067..d777663 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -210,6 +210,7 @@ static void usage(int op, const char * const myname)
 		addlist(_("  -v, --verbose        be verbose\n"));
 		addlist(_("      --arch <arch>    set an alternate architecture\n"));
 		addlist(_("      --cachedir <dir> set an alternate package cache location\n"));
+		addlist(_("      --hookdir <dir>  set an alternate hook location\n"));
 		addlist(_("      --color <when>   colorize the output\n"));
 		addlist(_("      --config <path>  set an alternate configuration file\n"));
 		addlist(_("      --debug          display debug messages\n"));
@@ -463,6 +464,9 @@ static int parsearg_global(int opt)
 			free(config->gpgdir);
 			config->gpgdir = strdup(optarg);
 			break;
+		case OP_HOOKDIR:
+			config->hookdirs = alpm_list_add(config->hookdirs, strdup(optarg));
+			break;
 		case OP_LOGFILE:
 			free(config->logfile);
 			config->logfile = strndup(optarg, PATH_MAX);
@@ -959,6 +963,7 @@ static int parseargs(int argc, char *argv[])
 		{"noscriptlet", no_argument,      0, OP_NOSCRIPTLET},
 		{"ask",        required_argument, 0, OP_ASK},
 		{"cachedir",   required_argument, 0, OP_CACHEDIR},
+		{"hookdir",    required_argument, 0, OP_HOOKDIR},
 		{"asdeps",     no_argument,       0, OP_ASDEPS},
 		{"logfile",    required_argument, 0, OP_LOGFILE},
 		{"ignoregroup", required_argument, 0, OP_IGNOREGROUP},
@@ -1274,6 +1279,11 @@ int main(int argc, char *argv[])
 			printf("%s  ", (const char *)j->data);
 		}
 		printf("\n");
+		printf("Hook Dirs : ");
+		for(j = alpm_option_get_hookdirs(config->handle); j; j = alpm_list_next(j)) {
+			printf("%s  ", (const char *)j->data);
+		}
+		printf("\n");
 		printf("Lock File : %s\n", alpm_option_get_lockfile(config->handle));
 		printf("Log File  : %s\n", alpm_option_get_logfile(config->handle));
 		printf("GPG Dir   : %s\n", alpm_option_get_gpgdir(config->handle));
-- 
2.6.1


More information about the pacman-dev mailing list