diff options
author | Giteabot <teabot@gitea.io> | 2023-06-14 02:36:52 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-14 08:36:52 +0200 |
commit | 21cd5c2f3d5c3914096f1ecfb2d2f1d13165caa4 (patch) | |
tree | 387e8150a764ef690cbb58a0f23e026b8e985b3b /models | |
parent | 22948048b2637495ace3091c0e0a9c6a0d96ec30 (diff) | |
download | gitea-21cd5c2f3d5c3914096f1ecfb2d2f1d13165caa4.tar.gz gitea-21cd5c2f3d5c3914096f1ecfb2d2f1d13165caa4.zip |
Fix all possible setting error related storages and added some tests (#23911) (#25244)
Backport #23911 by @lunny
Follow up #22405
Fix #20703
This PR rewrites storage configuration read sequences with some breaks
and tests. It becomes more strict than before and also fixed some
inherit problems.
- Move storage's MinioConfig struct into setting, so after the
configuration loading, the values will be stored into the struct but not
still on some section.
- All storages configurations should be stored on one section,
configuration items cannot be overrided by multiple sections. The
prioioty of configuration is `[attachment]` > `[storage.attachments]` |
`[storage.customized]` > `[storage]` > `default`
- For extra override configuration items, currently are `SERVE_DIRECT`,
`MINIO_BASE_PATH`, `MINIO_BUCKET`, which could be configured in another
section. The prioioty of the override configuration is `[attachment]` >
`[storage.attachments]` > `default`.
- Add more tests for storages configurations.
- Update the storage documentations.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'models')
-rw-r--r-- | models/migrations/v1_10/v96.go | 2 | ||||
-rw-r--r-- | models/migrations/v1_11/v112.go | 2 | ||||
-rw-r--r-- | models/migrations/v1_11/v115.go | 8 |
3 files changed, 6 insertions, 6 deletions
diff --git a/models/migrations/v1_10/v96.go b/models/migrations/v1_10/v96.go index 422defe838..34c8240031 100644 --- a/models/migrations/v1_10/v96.go +++ b/models/migrations/v1_10/v96.go @@ -53,7 +53,7 @@ func DeleteOrphanedAttachments(x *xorm.Engine) error { for _, attachment := range attachments { uuid := attachment.UUID - if err := util.RemoveAll(filepath.Join(setting.Attachment.Path, uuid[0:1], uuid[1:2], uuid)); err != nil { + if err := util.RemoveAll(filepath.Join(setting.Attachment.Storage.Path, uuid[0:1], uuid[1:2], uuid)); err != nil { return err } } diff --git a/models/migrations/v1_11/v112.go b/models/migrations/v1_11/v112.go index ff1f972204..0857663119 100644 --- a/models/migrations/v1_11/v112.go +++ b/models/migrations/v1_11/v112.go @@ -30,7 +30,7 @@ func RemoveAttachmentMissedRepo(x *xorm.Engine) error { for i := 0; i < len(attachments); i++ { uuid := attachments[i].UUID - if err = util.RemoveAll(filepath.Join(setting.Attachment.Path, uuid[0:1], uuid[1:2], uuid)); err != nil { + if err = util.RemoveAll(filepath.Join(setting.Attachment.Storage.Path, uuid[0:1], uuid[1:2], uuid)); err != nil { fmt.Printf("Error: %v", err) //nolint:forbidigo } } diff --git a/models/migrations/v1_11/v115.go b/models/migrations/v1_11/v115.go index da935f6514..8c631cfd0b 100644 --- a/models/migrations/v1_11/v115.go +++ b/models/migrations/v1_11/v115.go @@ -61,7 +61,7 @@ func RenameExistingUserAvatarName(x *xorm.Engine) error { for _, user := range users { oldAvatar := user.Avatar - if stat, err := os.Stat(filepath.Join(setting.Avatar.Path, oldAvatar)); err != nil || !stat.Mode().IsRegular() { + if stat, err := os.Stat(filepath.Join(setting.Avatar.Storage.Path, oldAvatar)); err != nil || !stat.Mode().IsRegular() { if err == nil { err = fmt.Errorf("Error: \"%s\" is not a regular file", oldAvatar) } @@ -86,7 +86,7 @@ func RenameExistingUserAvatarName(x *xorm.Engine) error { return fmt.Errorf("[user: %s] user table update: %w", user.LowerName, err) } - deleteList.Add(filepath.Join(setting.Avatar.Path, oldAvatar)) + deleteList.Add(filepath.Join(setting.Avatar.Storage.Path, oldAvatar)) migrated++ select { case <-ticker.C: @@ -135,7 +135,7 @@ func RenameExistingUserAvatarName(x *xorm.Engine) error { // copyOldAvatarToNewLocation copies oldAvatar to newAvatarLocation // and returns newAvatar location func copyOldAvatarToNewLocation(userID int64, oldAvatar string) (string, error) { - fr, err := os.Open(filepath.Join(setting.Avatar.Path, oldAvatar)) + fr, err := os.Open(filepath.Join(setting.Avatar.Storage.Path, oldAvatar)) if err != nil { return "", fmt.Errorf("os.Open: %w", err) } @@ -151,7 +151,7 @@ func copyOldAvatarToNewLocation(userID int64, oldAvatar string) (string, error) return newAvatar, nil } - if err := os.WriteFile(filepath.Join(setting.Avatar.Path, newAvatar), data, 0o666); err != nil { + if err := os.WriteFile(filepath.Join(setting.Avatar.Storage.Path, newAvatar), data, 0o666); err != nil { return "", fmt.Errorf("os.WriteFile: %w", err) } |