aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-git-receiver
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2018-05-31 02:08:08 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2018-05-31 02:08:11 +0200
commit56e07b6224fce7e213bfb9b4d00b93628a50aca7 (patch)
tree49c81bc0ce71242ec53d964211f3901ded650e36 /src/blogc-git-receiver
parent316bd60579ea11daca4fa25e2720b7fa147cc7ba (diff)
downloadblogc-56e07b6224fce7e213bfb9b4d00b93628a50aca7.tar.gz
blogc-56e07b6224fce7e213bfb9b4d00b93628a50aca7.tar.bz2
blogc-56e07b6224fce7e213bfb9b4d00b93628a50aca7.zip
git-receiver: allow users to define the htdocs symlink path
documentation pending
Diffstat (limited to 'src/blogc-git-receiver')
-rw-r--r--src/blogc-git-receiver/pre-receive.c52
1 files changed, 33 insertions, 19 deletions
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index 3668f8b..897e8f0 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -96,6 +96,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
char *master = NULL;
char *output_dir = NULL;
char *tmpdir = NULL;
+ char *sym = NULL;
char *hooks_dir = dirname(argv[0]); // this was validated by main()
char *real_hooks_dir = realpath(hooks_dir, NULL);
@@ -112,17 +113,37 @@ bgr_pre_receive_hook(int argc, char *argv[])
goto cleanup;
}
+ bc_config_t *config = bgr_settings_parse();
+ if (config == NULL) {
+ goto default_sym;
+ }
+
+ char *section = bgr_settings_get_section(config, repo_dir);
+ if (section == NULL) {
+ bc_config_free(config);
+ goto default_sym;
+ }
+
+ const char *sym_tmp = bc_config_get(config, section, "symlink");
+ sym = bc_str_starts_with(sym_tmp, "/") ? bc_strdup(sym_tmp) :
+ bc_strdup_printf("%s/%s", repo_dir, sym_tmp);
+ free(section);
+ bc_config_free(config);
+
+default_sym:
+
+ if (sym == NULL) {
+ sym = bc_strdup_printf("%s/htdocs", repo_dir);
+ }
+
if (NULL == getenv("GIT_DIR")) {
- char *htdocs_sym = bc_strdup_printf("%s/htdocs", repo_dir);
- if (0 != access(htdocs_sym, R_OK)) {
+ if (0 != access(sym, R_OK)) {
fprintf(stderr, "error: no previous build found. nothing to "
"rebuild.\n");
- free(htdocs_sym);
rv = 3;
goto cleanup;
}
- char *build_dir = realpath(htdocs_sym, NULL);
- free(htdocs_sym);
+ char *build_dir = realpath(sym, NULL);
if (build_dir == NULL) {
fprintf(stderr, "error: failed to get the hash of last built "
"commit.\n");
@@ -246,26 +267,18 @@ bgr_pre_receive_hook(int argc, char *argv[])
}
free(build_cmd);
- if (0 != chdir(repo_dir)) {
- fprintf(stderr, "error: failed to chdir (%s): %s\n", repo_dir,
+ char *htdocs_sym = realpath(sym, NULL);
+ if ((htdocs_sym != NULL) && (0 != unlink(sym))) {
+ fprintf(stderr, "error: failed to remove symlink (%s): %s\n", sym,
strerror(errno));
rmdir_recursive(output_dir);
rv = 3;
- goto cleanup;
- }
-
- char *htdocs_sym = realpath("htdocs", NULL);
- if ((htdocs_sym != NULL) && (0 != unlink("htdocs"))) {
- fprintf(stderr, "error: failed to remove symlink (%s/htdocs): %s\n",
- repo_dir, strerror(errno));
- rmdir_recursive(output_dir);
- rv = 3;
goto cleanup2;
}
- if (0 != symlink(output_dir, "htdocs")) {
- fprintf(stderr, "error: failed to create symlink (%s/htdocs): %s\n",
- repo_dir, strerror(errno));
+ if (0 != symlink(output_dir, sym)) {
+ fprintf(stderr, "error: failed to create symlink (%s): %s\n", sym,
+ strerror(errno));
rmdir_recursive(output_dir);
rv = 3;
goto cleanup2;
@@ -278,6 +291,7 @@ cleanup2:
free(htdocs_sym);
cleanup:
+ free(sym);
free(master);
free(output_dir);
rmdir_recursive(tmpdir);