Skip to content

Commit d18344b

Browse files
committed
Fix Storage mapping (go-gitea#13297)
Backport go-gitea#13297 This PR fixes several bugs in setting storage * The default STORAGE_TYPE should be the provided type. * The Storage config should be passed in to NewStorage as a pointer - otherwise the Mappable interface function MapTo will not be found * There was a bug in the MapTo function. Fix go-gitea#13286 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 151daf7 commit d18344b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

modules/setting/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Storage struct {
2121

2222
// MapTo implements the Mappable interface
2323
func (s *Storage) MapTo(v interface{}) error {
24-
pathValue := reflect.ValueOf(v).FieldByName("Path")
24+
pathValue := reflect.ValueOf(v).Elem().FieldByName("Path")
2525
if pathValue.IsValid() && pathValue.Kind() == reflect.String {
2626
pathValue.SetString(s.Path)
2727
}
@@ -46,7 +46,7 @@ func getStorage(name, typ string, overrides ...*ini.Section) Storage {
4646

4747
var storage Storage
4848

49-
storage.Type = sec.Key("STORAGE_TYPE").MustString("")
49+
storage.Type = sec.Key("STORAGE_TYPE").MustString(typ)
5050
storage.ServeDirect = sec.Key("SERVE_DIRECT").MustBool(false)
5151

5252
// Global Defaults

modules/storage/storage.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"net/url"
1313
"os"
1414

15+
"code.gitea.io/gitea/modules/log"
1516
"code.gitea.io/gitea/modules/setting"
1617
)
1718

@@ -141,21 +142,25 @@ func NewStorage(typStr string, cfg interface{}) (ObjectStorage, error) {
141142
}
142143

143144
func initAvatars() (err error) {
144-
Avatars, err = NewStorage(setting.Avatar.Storage.Type, setting.Avatar.Storage)
145+
log.Info("Initialising Avatar storage with type: %s", setting.Avatar.Storage.Type)
146+
Avatars, err = NewStorage(setting.Avatar.Storage.Type, &setting.Avatar.Storage)
145147
return
146148
}
147149

148150
func initAttachments() (err error) {
149-
Attachments, err = NewStorage(setting.Attachment.Storage.Type, setting.Attachment.Storage)
151+
log.Info("Initialising Attachment storage with type: %s", setting.Attachment.Storage.Type)
152+
Attachments, err = NewStorage(setting.Attachment.Storage.Type, &setting.Attachment.Storage)
150153
return
151154
}
152155

153156
func initLFS() (err error) {
154-
LFS, err = NewStorage(setting.LFS.Storage.Type, setting.LFS.Storage)
157+
log.Info("Initialising LFS storage with type: %s", setting.LFS.Storage.Type)
158+
LFS, err = NewStorage(setting.LFS.Storage.Type, &setting.LFS.Storage)
155159
return
156160
}
157161

158162
func initRepoAvatars() (err error) {
159-
RepoAvatars, err = NewStorage(setting.RepoAvatar.Storage.Type, setting.RepoAvatar.Storage)
163+
log.Info("Initialising Repository Avatar storage with type: %s", setting.RepoAvatar.Storage.Type)
164+
RepoAvatars, err = NewStorage(setting.RepoAvatar.Storage.Type, &setting.RepoAvatar.Storage)
160165
return
161166
}

0 commit comments

Comments
 (0)