pre-receive, update and post-receive hooks not automatically recreated with executable permissions #4360

Closed
opened 2025-11-02 05:48:06 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @djpbessems on GitHub (Nov 20, 2019).

  • Gitea version (or commit ref): 1.10.0
  • Git version:
    2.22.0
  • Operating system: docker
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist: No relevant log entries

Description

When the pre-receive, update and post-receive hooks have lost their executable permission (due to reasons not directly relevant to the actual bug), they should be automatically recreated with +x permission (see dfd8b94923/models/repo.go (L1114-L1150))

However, it turns out that this is not the case, apparently because ioutil.WriteFile does not change permissions on existing files.
Proposed solution by Zeripath: just need to call os.Chmod afterwards

Originally created by @djpbessems on GitHub (Nov 20, 2019). - Gitea version (or commit ref): 1.10.0 - Git version: 2.22.0 - Operating system: docker - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [x] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: No relevant log entries ## Description When the pre-receive, update and post-receive hooks have lost their executable permission (due to reasons not directly relevant to the actual bug), they should be automatically recreated with +x permission (see https://github.com/go-gitea/gitea/blob/dfd8b94923b90edbd3109f5afc3670fb1012e9c8/models/repo.go#L1114-L1150) However, it turns out that this is not the case, apparently because ioutil.WriteFile does not change permissions on existing files. Proposed solution by Zeripath: just need to call os.Chmod afterwards
GiteaMirror added the type/enhancement label 2025-11-02 05:48:06 -06:00
Author
Owner

@lunny commented on GitHub (Nov 20, 2019):

So isn't this a bug of ioutil.WriteFile?

@lunny commented on GitHub (Nov 20, 2019): So isn't this a bug of `ioutil.WriteFile`?
Author
Owner

@zeripath commented on GitHub (Nov 20, 2019):

nope it's subtle but it's clear that it doesn't change the mode of the file if it already exists.

@zeripath commented on GitHub (Nov 20, 2019): nope it's subtle but it's clear that it doesn't change the mode of the file if it already exists.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#4360