summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2015-10-16 20:28:23 -0400
committerAllan McRae <allan@archlinux.org>2015-10-18 10:59:23 +1000
commitc261210ccf0a7d08c7b3f24aee40b7c8d900e6ac (patch)
treed9b2ac4e97450e5c36fef318e02c6eb170fec3f1 /lib
parent46a1ac642907039a64f2ec93d352508b2ba3ba79 (diff)
downloadpacman-c261210ccf0a7d08c7b3f24aee40b7c8d900e6ac.tar.xz
handle: add hookdirs option
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/Makefile.am1
-rw-r--r--lib/libalpm/alpm.c5
-rw-r--r--lib/libalpm/alpm.h9
-rw-r--r--lib/libalpm/handle.c59
-rw-r--r--lib/libalpm/handle.h1
5 files changed, 75 insertions, 0 deletions
diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am
index f66daedf..1668da15 100644
--- a/lib/libalpm/Makefile.am
+++ b/lib/libalpm/Makefile.am
@@ -7,6 +7,7 @@ include_HEADERS = alpm_list.h alpm.h
AM_CPPFLAGS = \
-imacros $(top_builddir)/config.h \
+ -DSYSHOOKDIR=\"@datarootdir@/libalpm/hooks/\" \
-DLOCALEDIR=\"@localedir@\"
AM_CFLAGS = -pedantic -D_GNU_SOURCE $(WARNING_CFLAGS)
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index d77b43ab..0798c0bc 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -50,6 +50,7 @@ alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath,
{
alpm_errno_t myerr;
const char *lf = "db.lck";
+ char *hookdir;
size_t lockfilelen;
alpm_handle_t *myhandle = _alpm_handle_new();
@@ -64,6 +65,10 @@ alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath,
goto cleanup;
}
+ MALLOC(hookdir, strlen(myhandle->root) + strlen(SYSHOOKDIR) + 1, goto cleanup);
+ sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR);
+ myhandle->hookdirs = alpm_list_add(NULL, hookdir);
+
/* set default database extension */
STRDUP(myhandle->dbext, ".db", goto cleanup);
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 594f0b6d..f2249274 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -775,6 +775,15 @@ int alpm_option_add_cachedir(alpm_handle_t *handle, const char *cachedir);
int alpm_option_remove_cachedir(alpm_handle_t *handle, const char *cachedir);
/** @} */
+/** @name Accessors to the list of package hook directories.
+ * @{
+ */
+alpm_list_t *alpm_option_get_hookdirs(alpm_handle_t *handle);
+int alpm_option_set_hookdirs(alpm_handle_t *handle, alpm_list_t *hookdirs);
+int alpm_option_add_hookdir(alpm_handle_t *handle, const char *hookdir);
+int alpm_option_remove_hookdir(alpm_handle_t *handle, const char *hookdir);
+/** @} */
+
/** Returns the logfile name. */
const char *alpm_option_get_logfile(alpm_handle_t *handle);
/** Sets the logfile name. */
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index a12ac50d..98420b07 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -83,6 +83,7 @@ void _alpm_handle_free(alpm_handle_t *handle)
FREE(handle->dbpath);
FREE(handle->dbext);
FREELIST(handle->cachedirs);
+ FREELIST(handle->hookdirs);
FREE(handle->logfile);
FREE(handle->lockfile);
FREE(handle->arch);
@@ -207,6 +208,12 @@ const char SYMEXPORT *alpm_option_get_dbpath(alpm_handle_t *handle)
return handle->dbpath;
}
+alpm_list_t SYMEXPORT *alpm_option_get_hookdirs(alpm_handle_t *handle)
+{
+ CHECK_HANDLE(handle, return NULL);
+ return handle->hookdirs;
+}
+
alpm_list_t SYMEXPORT *alpm_option_get_cachedirs(alpm_handle_t *handle)
{
CHECK_HANDLE(handle, return NULL);
@@ -387,6 +394,58 @@ alpm_errno_t _alpm_set_directory_option(const char *value,
return 0;
}
+int SYMEXPORT alpm_option_add_hookdir(alpm_handle_t *handle, const char *hookdir)
+{
+ char *newhookdir;
+
+ CHECK_HANDLE(handle, return -1);
+ ASSERT(hookdir != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
+
+ newhookdir = canonicalize_path(hookdir);
+ if(!newhookdir) {
+ RET_ERR(handle, ALPM_ERR_MEMORY, -1);
+ }
+ handle->hookdirs = alpm_list_add(handle->hookdirs, newhookdir);
+ _alpm_log(handle, ALPM_LOG_DEBUG, "option 'hookdir' = %s\n", newhookdir);
+ return 0;
+}
+
+int SYMEXPORT alpm_option_set_hookdirs(alpm_handle_t *handle, alpm_list_t *hookdirs)
+{
+ alpm_list_t *i;
+ CHECK_HANDLE(handle, return -1);
+ if(handle->hookdirs) {
+ FREELIST(handle->hookdirs);
+ }
+ for(i = hookdirs; i; i = i->next) {
+ int ret = alpm_option_add_hookdir(handle, i->data);
+ if(ret) {
+ return ret;
+ }
+ }
+ return 0;
+}
+
+int SYMEXPORT alpm_option_remove_hookdir(alpm_handle_t *handle, const char *hookdir)
+{
+ char *vdata = NULL;
+ char *newhookdir;
+ CHECK_HANDLE(handle, return -1);
+ ASSERT(hookdir != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
+
+ newhookdir = canonicalize_path(hookdir);
+ if(!newhookdir) {
+ RET_ERR(handle, ALPM_ERR_MEMORY, -1);
+ }
+ handle->hookdirs = alpm_list_remove_str(handle->hookdirs, newhookdir, &vdata);
+ FREE(newhookdir);
+ if(vdata != NULL) {
+ FREE(vdata);
+ return 1;
+ }
+ return 0;
+}
+
int SYMEXPORT alpm_option_add_cachedir(alpm_handle_t *handle, const char *cachedir)
{
char *newcachedir;
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index 315d9878..e252fbf6 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -82,6 +82,7 @@ struct __alpm_handle_t {
char *lockfile; /* Name of the lock file */
char *gpgdir; /* Directory where GnuPG files are stored */
alpm_list_t *cachedirs; /* Paths to pacman cache directories */
+ alpm_list_t *hookdirs; /* Paths to hook directories */
/* package lists */
alpm_list_t *noupgrade; /* List of packages NOT to be upgraded */