diff options
| author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-06-12 18:45:32 +0200 | 
|---|---|---|
| committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-06-12 16:32:19 +0200 | 
| commit | 76448e806720d99a57f492fbaeff44bf3250b914 (patch) | |
| tree | cd24992275917a00de7a0d31081ee00e1f3dcecc | |
| parent | 4a50ba03e31295a4c37ec2576fe113751a7f32ec (diff) | |
| download | blogc-76448e806720d99a57f492fbaeff44bf3250b914.tar.gz blogc-76448e806720d99a57f492fbaeff44bf3250b914.tar.bz2 blogc-76448e806720d99a57f492fbaeff44bf3250b914.zip | |
git-receiver: git shell should reinstall hooks if symlinks are broken
| -rw-r--r-- | src/blogc-git-receiver/shell.c | 15 | ||||
| -rwxr-xr-x | tests/blogc-git-receiver/check_shell.sh.in | 15 | 
2 files changed, 28 insertions, 2 deletions
| diff --git a/src/blogc-git-receiver/shell.c b/src/blogc-git-receiver/shell.c index 8c45b54..d288654 100644 --- a/src/blogc-git-receiver/shell.c +++ b/src/blogc-git-receiver/shell.c @@ -19,6 +19,17 @@  #include "shell.h" +static bool +lexists(const char *pathname) +{ +    struct stat b; +    int tmp_errno = errno; +    bool rv = lstat(pathname, &b) == 0; +    errno = tmp_errno; +    return rv; +} + +  int  bgr_shell(int argc, char *argv[])  { @@ -96,7 +107,7 @@ bgr_shell(int argc, char *argv[])          goto cleanup;      } -    if (0 == access("pre-receive", F_OK)) { +    if (lexists("pre-receive")) {          if (0 != unlink("pre-receive")) {              fprintf(stderr, "error: failed to remove old symlink "                  "(%s/hooks/pre-receive): %s\n", repo, strerror(errno)); @@ -112,7 +123,7 @@ bgr_shell(int argc, char *argv[])          goto cleanup;      } -    if (0 == access("post-receive", F_OK)) { +    if (lexists("post-receive")) {          if (0 != unlink("post-receive")) {              fprintf(stderr, "error: failed to remove old symlink "                  "(%s/hooks/post-receive): %s\n", repo, strerror(errno)); diff --git a/tests/blogc-git-receiver/check_shell.sh.in b/tests/blogc-git-receiver/check_shell.sh.in index 8743293..f70fc50 100755 --- a/tests/blogc-git-receiver/check_shell.sh.in +++ b/tests/blogc-git-receiver/check_shell.sh.in @@ -36,6 +36,21 @@ fi  [[ -h "${TEMP}/repos/lol.git/hooks/post-receive" ]]  [[ "$(readlink "${TEMP}/repos/lol.git/hooks/post-receive")" == "${SELF}" ]] +rm "${TEMP}/repos/lol.git/hooks/pre-receive" +ln -s /lolheheasdxd "${TEMP}/repos/lol.git/hooks/pre-receive" + +echo 0000 | call_bgr -c "git-receive-pack 'lol.git'" 2>&1 > "${TEMP}/output.txt" +if [[ -n "${VALGRIND}" ]]; then +    grep "git-shell -c \"git-receive-pack '.*repos/lol.git'\"" "${TEMP}/output.txt" &> /dev/null +else +    grep "agent=" "${TEMP}/output.txt" &> /dev/null +fi +[[ -d "${TEMP}/repos/lol.git" ]] +[[ -h "${TEMP}/repos/lol.git/hooks/pre-receive" ]] +[[ "$(readlink "${TEMP}/repos/lol.git/hooks/pre-receive")" == "${SELF}" ]] +[[ -h "${TEMP}/repos/lol.git/hooks/post-receive" ]] +[[ "$(readlink "${TEMP}/repos/lol.git/hooks/post-receive")" == "${SELF}" ]] +  cat > "${TEMP}/tmp.txt" <<EOF  blob  mark :1 | 
