diff options
author | KN4CK3R <KN4CK3R@users.noreply.github.com> | 2021-05-29 20:44:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-29 19:44:14 +0100 |
commit | efe77eec85fd6524ceb66cacb35f054c2a180738 (patch) | |
tree | 775ab2184fdbc8e8c04ead2c27df4a6948aa9572 /cmd | |
parent | 2a998048efdf57a5ceacc9c6f4d2d6120494d2b7 (diff) | |
download | gitea-efe77eec85fd6524ceb66cacb35f054c2a180738.tar.gz gitea-efe77eec85fd6524ceb66cacb35f054c2a180738.zip |
Unified custom config creation (#16012)
* Unified custom config creation.
* Fixed log message.
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/web.go | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/cmd/web.go b/cmd/web.go index 3a5c36833b..9c7d493339 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -16,7 +16,6 @@ import ( "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/routers" "code.gitea.io/gitea/routers/routes" @@ -152,19 +151,6 @@ func setPort(port string) error { case setting.FCGI: case setting.FCGIUnix: default: - // Save LOCAL_ROOT_URL if port changed - cfg := ini.Empty() - isFile, err := util.IsFile(setting.CustomConf) - if err != nil { - log.Fatal("Unable to check if %s is a file", err) - } - if isFile { - // Keeps custom settings if there is already something. - if err := cfg.Append(setting.CustomConf); err != nil { - return fmt.Errorf("Failed to load custom conf '%s': %v", setting.CustomConf, err) - } - } - defaultLocalURL := string(setting.Protocol) + "://" if setting.HTTPAddr == "0.0.0.0" { defaultLocalURL += "localhost" @@ -173,10 +159,10 @@ func setPort(port string) error { } defaultLocalURL += ":" + setting.HTTPPort + "/" - cfg.Section("server").Key("LOCAL_ROOT_URL").SetValue(defaultLocalURL) - if err := cfg.SaveTo(setting.CustomConf); err != nil { - return fmt.Errorf("Error saving generated LOCAL_ROOT_URL to custom config: %v", err) - } + // Save LOCAL_ROOT_URL if port changed + setting.CreateOrAppendToCustomConf(func(cfg *ini.File) { + cfg.Section("server").Key("LOCAL_ROOT_URL").SetValue(defaultLocalURL) + }) } return nil } |