summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2016-01-07 18:23:09 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2016-01-07 19:09:46 +0100
commit767214e4f157ae4a74be0b557bd49e24d972970b (patch)
tree46ee50d0e2c729e2892db8c96abc61294980a5fe /src/io.c
parentddfe49d9feeba0d280e501f67cda64646e79d901 (diff)
downloadcalcurse-767214e4f157ae4a74be0b557bd49e24d972970b.zip
Add pre-save and post-save hooks
This adds support for hooks which are executed before/after saving calcurse data. Hooks can be placed under hooks/pre-save and hooks/post-save in the data directory and need to be executable. Potential use cases include: * Automatically commit any changes to the data files using a VCS. * Automatically sync with some sever component on data file changes. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/io.c b/src/io.c
index f12bac9..7411a6b 100644
--- a/src/io.c
+++ b/src/io.c
@@ -239,6 +239,7 @@ void io_init(const char *cfile, const char *datadir)
snprintf(path_dpid, BUFSIZ, "%s/" DPID_PATH_NAME, home);
snprintf(path_dmon_log, BUFSIZ, "%s/" DLOG_PATH_NAME,
home);
+ snprintf(path_hooks, BUFSIZ, "%s/" HOOKS_DIR_NAME, home);
} else {
home = getenv("HOME");
if (home == NULL) {
@@ -252,6 +253,7 @@ void io_init(const char *cfile, const char *datadir)
snprintf(path_dpid, BUFSIZ, "%s/" DPID_PATH, home);
snprintf(path_dmon_log, BUFSIZ, "%s/" DLOG_PATH, home);
snprintf(path_notes, BUFSIZ, "%s/" NOTES_DIR, home);
+ snprintf(path_hooks, BUFSIZ, "%s/" HOOKS_DIR, home);
}
if (cfile == NULL) {
@@ -391,6 +393,7 @@ void io_save_cal(enum save_display display)
if (read_only)
return;
+ run_hook("pre-save");
pthread_mutex_lock(&io_save_mutex);
show_bar = 0;
@@ -428,6 +431,7 @@ void io_save_cal(enum save_display display)
}
pthread_mutex_unlock(&io_save_mutex);
+ run_hook("post-save");
}
static void io_load_error(const char *filename, unsigned line,