diff options
author | 胡玮文 <huww98@outlook.com> | 2020-12-22 01:59:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-21 18:59:18 +0100 |
commit | addd4248daf2f90c5ce54f2d37c268ebab491b4a (patch) | |
tree | ca0b73e9debcea7a59e797c8deaf387fda068b95 /modules/setting/storage.go | |
parent | 9271040c21580963a6f26a13cf4510893242c572 (diff) | |
download | gitea-addd4248daf2f90c5ce54f2d37c268ebab491b4a.tar.gz gitea-addd4248daf2f90c5ce54f2d37c268ebab491b4a.zip |
Fix storage config implementation (#14091)
The design is very flexible, but not implemented correctly.
This commit fixes several issues:
* Costom storage type stated in https://docs.gitea.io/en-us/config-cheat-sheet/#storage-storage
not working
* [storage.attachments], [storage.minio] section not respected
Signed-off-by: 胡玮文 <huww98@outlook.com>
Diffstat (limited to 'modules/setting/storage.go')
-rw-r--r-- | modules/setting/storage.go | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/modules/setting/storage.go b/modules/setting/storage.go index 27788da1ff..43890371fa 100644 --- a/modules/setting/storage.go +++ b/modules/setting/storage.go @@ -31,22 +31,10 @@ func (s *Storage) MapTo(v interface{}) error { return nil } -func getStorage(name, typ string, overrides ...*ini.Section) Storage { +func getStorage(name, typ string, targetSec *ini.Section) Storage { const sectionName = "storage" sec := Cfg.Section(sectionName) - if len(overrides) == 0 { - overrides = []*ini.Section{ - Cfg.Section(sectionName + "." + typ), - Cfg.Section(sectionName + "." + name), - } - } - - var storage Storage - - storage.Type = sec.Key("STORAGE_TYPE").MustString(typ) - storage.ServeDirect = sec.Key("SERVE_DIRECT").MustBool(false) - // Global Defaults sec.Key("MINIO_ENDPOINT").MustString("localhost:9000") sec.Key("MINIO_ACCESS_KEY_ID").MustString("") @@ -55,18 +43,22 @@ func getStorage(name, typ string, overrides ...*ini.Section) Storage { sec.Key("MINIO_LOCATION").MustString("us-east-1") sec.Key("MINIO_USE_SSL").MustBool(false) - storage.Section = sec - - for _, override := range overrides { - for _, key := range storage.Section.Keys() { - if !override.HasKey(key.Name()) { - _, _ = override.NewKey(key.Name(), key.Value()) + nameSec := Cfg.Section(sectionName + "." + name) + typeSec := Cfg.Section(sectionName + "." + typ) + for _, override := range []*ini.Section{nameSec, typeSec, sec} { + for _, key := range override.Keys() { + if !targetSec.HasKey(key.Name()) { + _, _ = targetSec.NewKey(key.Name(), key.Value()) } } - storage.ServeDirect = override.Key("SERVE_DIRECT").MustBool(false) - storage.Section = override } + 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 storage.Path = storage.Section.Key("PATH").MustString(filepath.Join(AppDataPath, name)) if !filepath.IsAbs(storage.Path) { |