summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-12-27 16:41:49 +0000
committerGitHub <noreply@github.com>2019-12-27 16:41:49 +0000
commit145c1ea0b6b1f79eff047041853378319117fd39 (patch)
treee660194fe2e50b8a6247423da974a0accb630e53 /models
parent154424623a0486a2dd1ab757aaa44d2237116b85 (diff)
downloadgitea-145c1ea0b6b1f79eff047041853378319117fd39.tar.gz
gitea-145c1ea0b6b1f79eff047041853378319117fd39.zip
Remove and recreate the hooks to set them executable with the umask (#9502)
Fix #9091
Diffstat (limited to 'models')
-rw-r--r--models/repo.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/models/repo.go b/models/repo.go
index 02cb3b9128..53a9196aa7 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -967,6 +967,7 @@ func CreateDelegateHooks(repoPath string) error {
// createDelegateHooks creates all the hooks scripts for the repo
func createDelegateHooks(repoPath string) (err error) {
+
var (
hookNames = []string{"pre-receive", "update", "post-receive"}
hookTpls = []string{
@@ -992,10 +993,16 @@ func createDelegateHooks(repoPath string) (err error) {
}
// WARNING: This will override all old server-side hooks
+ if err = os.Remove(oldHookPath); err != nil && !os.IsNotExist(err) {
+ return fmt.Errorf("unable to pre-remove old hook file '%s' prior to rewriting: %v ", oldHookPath, err)
+ }
if err = ioutil.WriteFile(oldHookPath, []byte(hookTpls[i]), 0777); err != nil {
return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err)
}
+ if err = os.Remove(newHookPath); err != nil && !os.IsNotExist(err) {
+ return fmt.Errorf("unable to pre-remove new hook file '%s' prior to rewriting: %v", newHookPath, err)
+ }
if err = ioutil.WriteFile(newHookPath, []byte(giteaHookTpls[i]), 0777); err != nil {
return fmt.Errorf("write new hook file '%s': %v", newHookPath, err)
}