Skip to content

Commit 172e7ee

Browse files
authored
Fix Storage mapping (#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 #13286 Signed-off-by: Andrew Thornton <[email protected]>
1 parent e2740b3 commit 172e7ee

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

modules/setting/storage.go

+2-2
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,24 @@ func NewStorage(typStr string, cfg interface{}) (ObjectStorage, error) {
143143

144144
func initAvatars() (err error) {
145145
log.Info("Initialising Avatar storage with type: %s", setting.Avatar.Storage.Type)
146-
Avatars, err = NewStorage(setting.Avatar.Storage.Type, setting.Avatar.Storage)
146+
Avatars, err = NewStorage(setting.Avatar.Storage.Type, &setting.Avatar.Storage)
147147
return
148148
}
149149

150150
func initAttachments() (err error) {
151151
log.Info("Initialising Attachment storage with type: %s", setting.Attachment.Storage.Type)
152-
Attachments, err = NewStorage(setting.Attachment.Storage.Type, setting.Attachment.Storage)
152+
Attachments, err = NewStorage(setting.Attachment.Storage.Type, &setting.Attachment.Storage)
153153
return
154154
}
155155

156156
func initLFS() (err error) {
157157
log.Info("Initialising LFS storage with type: %s", setting.LFS.Storage.Type)
158-
LFS, err = NewStorage(setting.LFS.Storage.Type, setting.LFS.Storage)
158+
LFS, err = NewStorage(setting.LFS.Storage.Type, &setting.LFS.Storage)
159159
return
160160
}
161161

162162
func initRepoAvatars() (err error) {
163163
log.Info("Initialising Repository Avatar storage with type: %s", setting.RepoAvatar.Storage.Type)
164-
RepoAvatars, err = NewStorage(setting.RepoAvatar.Storage.Type, setting.RepoAvatar.Storage)
164+
RepoAvatars, err = NewStorage(setting.RepoAvatar.Storage.Type, &setting.RepoAvatar.Storage)
165165
return
166166
}

0 commit comments

Comments
 (0)