Skip to content

Commit 71d2a6a

Browse files
GiteaBotwxiaoguang
andauthored
Use InitWorkPathAndCfgProvider for environment-to-ini to avoid unnecessary checks (#25480) (#25488)
Backport #25480 by @wxiaoguang Fix #25481 The `InitWorkPathAndCommonConfig` calls `LoadCommonSettings` which does many checks like "current user is root or not". Some commands like "environment-to-ini" shouldn't do such check, because it might be run with "root" user at the moment (eg: the docker's setup script) ps: in the future, the docker's setup script should be improved to avoid Gitea's command running with "root" Co-authored-by: wxiaoguang <[email protected]>
1 parent d1f1f11 commit 71d2a6a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

contrib/environment-to-ini/environment-to-ini.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func main() {
8888
}
8989

9090
func runEnvironmentToIni(c *cli.Context) error {
91-
setting.InitWorkPathAndCommonConfig(os.Getenv, setting.ArgWorkPathAndCustomConf{
91+
setting.InitWorkPathAndCfgProvider(os.Getenv, setting.ArgWorkPathAndCustomConf{
9292
WorkPath: c.String("work-path"),
9393
CustomPath: c.String("custom-path"),
9494
CustomConf: c.String("config"),

modules/setting/path.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ func (s *stringWithDefault) Set(v string) {
8989

9090
// InitWorkPathAndCommonConfig will set AppWorkPath, CustomPath and CustomConf, init default config provider by CustomConf and load common settings,
9191
func InitWorkPathAndCommonConfig(getEnvFn func(name string) string, args ArgWorkPathAndCustomConf) {
92+
InitWorkPathAndCfgProvider(getEnvFn, args)
93+
LoadCommonSettings()
94+
}
95+
96+
// InitWorkPathAndCfgProvider will set AppWorkPath, CustomPath and CustomConf, init default config provider by CustomConf
97+
func InitWorkPathAndCfgProvider(getEnvFn func(name string) string, args ArgWorkPathAndCustomConf) {
9298
tryAbsPath := func(paths ...string) string {
9399
s := paths[len(paths)-1]
94100
for i := len(paths) - 2; i >= 0; i-- {
@@ -186,6 +192,4 @@ func InitWorkPathAndCommonConfig(getEnvFn func(name string) string, args ArgWork
186192
AppWorkPath = tmpWorkPath.Value
187193
CustomPath = tmpCustomPath.Value
188194
CustomConf = tmpCustomConf.Value
189-
190-
LoadCommonSettings()
191195
}

0 commit comments

Comments
 (0)