aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-git-receiver/pre-receive.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/blogc-git-receiver/pre-receive.c')
-rw-r--r--src/blogc-git-receiver/pre-receive.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index 954c379..14d5ca2 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -93,7 +93,6 @@ int
bgr_pre_receive_hook(int argc, char *argv[])
{
int rv = 0;
- char buffer[4096];
char *master = NULL;
if (isatty(STDIN_FILENO)) {
@@ -148,15 +147,14 @@ bgr_pre_receive_hook(int argc, char *argv[])
char *repo_dir = NULL;
char *output_dir = NULL;
- if (NULL == getcwd(buffer, sizeof(buffer))) {
- fprintf(stderr, "error: failed to get repository remote path: %s\n",
+ repo_dir = getcwd(NULL, 0);
+ if (repo_dir == NULL) {
+ fprintf(stderr, "error: failed to get repository path: %s\n",
strerror(errno));
rv = 1;
goto cleanup;
}
- repo_dir = bc_strdup(buffer);
-
char dir[] = "/tmp/blogc_XXXXXX";
if (NULL == mkdtemp(dir)) {
rv = 1;
@@ -239,18 +237,13 @@ bgr_pre_receive_hook(int argc, char *argv[])
goto cleanup;
}
- char *htdocs_sym = NULL;
- ssize_t htdocs_sym_len = readlink("htdocs", buffer, sizeof(buffer));
- if (0 < htdocs_sym_len) {
- if (0 != unlink("htdocs")) {
- fprintf(stderr, "error: failed to remove symlink (%s/htdocs): %s\n",
- repo_dir, strerror(errno));
- rmdir_recursive(output_dir);
- rv = 1;
- goto cleanup;
- }
- buffer[htdocs_sym_len] = '\0';
- htdocs_sym = buffer;
+ 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 = 1;
+ goto cleanup2;
}
if (0 != symlink(output_dir, "htdocs")) {
@@ -258,12 +251,15 @@ bgr_pre_receive_hook(int argc, char *argv[])
repo_dir, strerror(errno));
rmdir_recursive(output_dir);
rv = 1;
- goto cleanup;
+ goto cleanup2;
}
if (htdocs_sym != NULL)
rmdir_recursive(htdocs_sym);
+cleanup2:
+ free(htdocs_sym);
+
cleanup:
free(master);
free(output_dir);