Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only request write when necessary #18657

Merged
merged 8 commits into from
Feb 8, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, 0o600)
Gusted marked this conversation as resolved.
Show resolved Hide resolved
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