Skip to content

Commit

Permalink
Only request write when necessary
Browse files Browse the repository at this point in the history
- Only request write for `INTERNAL_TOKEN_URI` when no token was found.
- Resolves go-gitea#18655
  • Loading branch information
Gusted committed Feb 7, 2022
1 parent 5faf055 commit 740aa78
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ func loadInternalToken(sec *ini.Section) string {
}
switch tempURI.Scheme {
case "file":
fp, err := os.OpenFile(tempURI.RequestURI(), os.O_RDWR, 0o600)
fp, err := os.OpenFile(tempURI.RequestURI(), os.O_RDONLY, 0o400)
if err != nil {
log.Fatal("Failed to open InternalTokenURI (%s): %v", uri, err)
}
Expand All @@ -1092,6 +1092,12 @@ func loadInternalToken(sec *ini.Section) string {
}
// No token in the file, generate one and store it.
if len(buf) == 0 {
fp.Close()
fp, err = os.OpenFile(tempURI.RequestURI(), os.O_WRONLY, 0o600)
if err != nil {
log.Fatal("Failed to open InternalTokenURI (%s): %v", uri, err)
}

token, err := generate.NewInternalToken()
if err != nil {
log.Fatal("Error generate internal token: %v", err)
Expand Down

0 comments on commit 740aa78

Please sign in to comment.