summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2015-10-17 02:28:27 +0200
committerAllan McRae <allan@archlinux.org>2015-10-18 02:59:23 +0200
commit7000bf919812f3ed56969a86b4aebf90e98ec6a3 (patch)
tree0cbf71072c97a77a5a65d8f15c7b508f078313d5
parente8e872c8f93ba13f67b882d64c16606973f0ff67 (diff)
downloadpacman-7000bf919812f3ed56969a86b4aebf90e98ec6a3.tar.gz
pacman-7000bf919812f3ed56969a86b4aebf90e98ec6a3.tar.xz
pacman: add user hook directories
Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--doc/pacman.conf.5.txt8
-rw-r--r--src/pacman/Makefile.am2
-rw-r--r--src/pacman/conf.c22
-rw-r--r--src/pacman/conf.h2
-rw-r--r--src/pacman/pacman.c10
5 files changed, 44 insertions, 0 deletions
diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt
index 383e0729..b78d1fe6 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 d3ae071e..b07c6706 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 738b0261..6a2b2067 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 3fff9008..cde67414 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 c680067c..d777663d 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));