aboutsummaryrefslogtreecommitdiffstats
path: root/modules/setting/storage.go
diff options
context:
space:
mode:
author胡玮文 <huww98@outlook.com>2020-12-22 07:03:18 +0800
committerGitHub <noreply@github.com>2020-12-22 01:03:18 +0200
commitc21a399646e3001841b095c2faa96b17f2483048 (patch)
treeb006e209bab6872f366abe4e953d146f86e5ca4d /modules/setting/storage.go
parentaddd4248daf2f90c5ce54f2d37c268ebab491b4a (diff)
downloadgitea-c21a399646e3001841b095c2faa96b17f2483048.tar.gz
gitea-c21a399646e3001841b095c2faa96b17f2483048.zip
more test case for STORAGE_TYPE overrides (and fixes) (#14096)
Signed-off-by: 胡玮文 <huww98@outlook.com>
Diffstat (limited to 'modules/setting/storage.go')
-rw-r--r--modules/setting/storage.go32
1 files changed, 24 insertions, 8 deletions
diff --git a/modules/setting/storage.go b/modules/setting/storage.go
index 43890371fa..3ab08d8d2a 100644
--- a/modules/setting/storage.go
+++ b/modules/setting/storage.go
@@ -43,20 +43,36 @@ func getStorage(name, typ string, targetSec *ini.Section) Storage {
sec.Key("MINIO_LOCATION").MustString("us-east-1")
sec.Key("MINIO_USE_SSL").MustBool(false)
- nameSec := Cfg.Section(sectionName + "." + name)
- typeSec := Cfg.Section(sectionName + "." + typ)
- for _, override := range []*ini.Section{nameSec, typeSec, sec} {
+ var storage Storage
+ storage.Section = targetSec
+ storage.Type = typ
+
+ overrides := make([]*ini.Section, 0, 3)
+ nameSec, err := Cfg.GetSection(sectionName + "." + name)
+ if err == nil {
+ overrides = append(overrides, nameSec)
+ }
+
+ typeSec, err := Cfg.GetSection(sectionName + "." + typ)
+ if err == nil {
+ overrides = append(overrides, typeSec)
+ nextType := typeSec.Key("STORAGE_TYPE").String()
+ if len(nextType) > 0 {
+ storage.Type = nextType // Support custom STORAGE_TYPE
+ }
+ }
+ overrides = append(overrides, sec)
+
+ for _, override := range overrides {
for _, key := range override.Keys() {
if !targetSec.HasKey(key.Name()) {
_, _ = targetSec.NewKey(key.Name(), key.Value())
}
}
+ if len(storage.Type) == 0 {
+ storage.Type = override.Key("STORAGE_TYPE").String()
+ }
}
-
- var storage Storage
- storage.Section = targetSec
-
- storage.Type = typeSec.Key("STORAGE_TYPE").MustString(typ)
storage.ServeDirect = storage.Section.Key("SERVE_DIRECT").MustBool(false)
// Specific defaults