diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-06-21 10:31:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-21 10:31:40 +0800 |
commit | df5cf5ddbd9099a121d5074a0b2a710fd71309fd (patch) | |
tree | 61844c68b8c38a2d24a90fc62c75aa0ef8522005 /modules/setting/security.go | |
parent | 831db53c214f81e5eaf055716a42865007cb8123 (diff) | |
download | gitea-df5cf5ddbd9099a121d5074a0b2a710fd71309fd.tar.gz gitea-df5cf5ddbd9099a121d5074a0b2a710fd71309fd.zip |
Avoid polluting config file when "save" (#25395)
That's a longstanding INI package problem: the "MustXxx" calls change
the option values, and the following "Save" will save a lot of garbage
options into the user's config file.
Ideally we should refactor the INI package to a clear solution, but it's
a huge work.
A clear workaround is what this PR does: when "Save", load a clear INI
instance and save it.
Partially fix #25377, the "install" page needs more fine tunes.
Diffstat (limited to 'modules/setting/security.go')
-rw-r--r-- | modules/setting/security.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/modules/setting/security.go b/modules/setting/security.go index ce2e7711f1..c39eb7f3eb 100644 --- a/modules/setting/security.go +++ b/modules/setting/security.go @@ -89,8 +89,13 @@ func generateSaveInternalToken(rootCfg ConfigProvider) { } InternalToken = token + saveCfg, err := rootCfg.PrepareSaving() + if err != nil { + log.Fatal("Error saving internal token: %v", err) + } rootCfg.Section("security").Key("INTERNAL_TOKEN").SetValue(token) - if err := rootCfg.Save(); err != nil { + saveCfg.Section("security").Key("INTERNAL_TOKEN").SetValue(token) + if err = saveCfg.Save(); err != nil { log.Fatal("Error saving internal token: %v", err) } } |