From 7000bf919812f3ed56969a86b4aebf90e98ec6a3 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 16 Oct 2015 20:28:27 -0400 Subject: pacman: add user hook directories Signed-off-by: Allan McRae --- src/pacman/conf.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/pacman/conf.c') 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); -- cgit v1.2.3-54-g00ecf