[pacman-dev] [PATCH v2 7/7] pacman: add user hook directories
Andrew Gregory
andrew.gregory.8 at gmail.com
Mon Sep 14 22:42:40 UTC 2015
---
doc/pacman.conf.5.txt | 8 ++++++++
src/pacman/Makefile.am | 2 ++
src/pacman/conf.c | 22 ++++++++++++++++++++++
src/pacman/conf.h | 1 +
4 files changed, 33 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..552ebd3 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..7ccc4dc 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;
--
2.5.2
More information about the pacman-dev
mailing list