diff options
author | zeripath <art27@cantab.net> | 2019-04-29 19:08:21 +0100 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-04-29 14:08:21 -0400 |
commit | 8d0d7bc28d517acc9ca98f0468d7ff2a4fdaf139 (patch) | |
tree | 0a8817abd2512ca2ebccfd4e5dc08814933aad2b /modules/setting | |
parent | ccf4783980effa871abaecd70d0f983c5062a187 (diff) | |
download | gitea-8d0d7bc28d517acc9ca98f0468d7ff2a4fdaf139.tar.gz gitea-8d0d7bc28d517acc9ca98f0468d7ff2a4fdaf139.zip |
Make CustomPath, CustomConf and AppWorkPath configurable at build (#6631)
Diffstat (limited to 'modules/setting')
-rw-r--r-- | modules/setting/setting.go | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 85fcbac2b1..692fb9820a 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -391,12 +391,12 @@ func getAppPath() (string, error) { } func getWorkPath(appPath string) string { - workPath := "" - giteaWorkPath := os.Getenv("GITEA_WORK_DIR") + workPath := AppWorkPath - if len(giteaWorkPath) > 0 { + if giteaWorkPath, ok := os.LookupEnv("GITEA_WORK_DIR"); ok { workPath = giteaWorkPath - } else { + } + if len(workPath) == 0 { i := strings.LastIndex(appPath, "/") if i == -1 { workPath = appPath @@ -475,27 +475,40 @@ func CheckLFSVersion() { } } -// NewContext initializes configuration context. -// NOTE: do not print any log except error. -func NewContext() { - Cfg = ini.Empty() - - CustomPath = os.Getenv("GITEA_CUSTOM") +// SetCustomPathAndConf will set CustomPath and CustomConf with reference to the +// GITEA_CUSTOM environment variable and with provided overrides before stepping +// back to the default +func SetCustomPathAndConf(providedCustom, providedConf string) { + if giteaCustom, ok := os.LookupEnv("GITEA_CUSTOM"); ok { + CustomPath = giteaCustom + } + if len(providedCustom) != 0 { + CustomPath = providedCustom + } if len(CustomPath) == 0 { CustomPath = path.Join(AppWorkPath, "custom") } else if !filepath.IsAbs(CustomPath) { CustomPath = path.Join(AppWorkPath, CustomPath) } - if len(CustomPID) > 0 { - createPIDFile(CustomPID) + if len(providedConf) != 0 { + CustomConf = providedConf } - if len(CustomConf) == 0 { CustomConf = path.Join(CustomPath, "conf/app.ini") } else if !filepath.IsAbs(CustomConf) { CustomConf = path.Join(CustomPath, CustomConf) } +} + +// NewContext initializes configuration context. +// NOTE: do not print any log except error. +func NewContext() { + Cfg = ini.Empty() + + if len(CustomPID) > 0 { + createPIDFile(CustomPID) + } if com.IsFile(CustomConf) { if err := Cfg.Append(CustomConf); err != nil { |