forgejo/services/forgejo/sanity_v1TOv5_0_1Included.go
Earl Warren f6ba73de4c
[UPGRADE] add sanity checks for [storage*]
Refs: https://forgejo.org/2023-08-release-v1-20-3-0/
(cherry picked from commit a266dd0ce3)
(cherry picked from commit b9eb5eccd8)
(cherry picked from commit 7fc2028ede)
(cherry picked from commit 0c988e6120)
(cherry picked from commit 7ba05e8c2b)
(cherry picked from commit 2ed5068abe)
(cherry picked from commit 353913a26d)
(cherry picked from commit 4e63a01a8b)
(cherry picked from commit 99f612aed3)
(cherry picked from commit b4fe189cae)
(cherry picked from commit bd35e3b7bc)
(cherry picked from commit f59d9f7088)
(cherry picked from commit 0b2a93e044)
(cherry picked from commit 8c5d8bfea0)
(cherry picked from commit 2817ce027c)
(cherry picked from commit 162056cbcf)
(cherry picked from commit 07152a0ba6)
(cherry picked from commit 72e3777915)
(cherry picked from commit 3b1ebd95b9)
(cherry picked from commit 14fc4f3fac)
(cherry picked from commit 9052c86e8c)
(cherry picked from commit 16f1cc21ea)
(cherry picked from commit 0fef12f5d8)
(cherry picked from commit d187381f73)
(cherry picked from commit 9dda715111)
2024-02-05 14:44:33 +01:00

92 lines
2.5 KiB
Go

// SPDX-License-Identifier: MIT
package forgejo
import (
"fmt"
"strings"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/forgejo/semver"
"code.gitea.io/gitea/modules/setting"
"github.com/hashicorp/go-version"
)
var v1TOv5_0_1IncludedStorageSections = []struct {
section string
storageSection string
}{
{"attachment", "storage.attachments"},
{"lfs", "storage.lfs"},
{"avatar", "storage.avatars"},
{"repo-avatar", "storage.repo-avatars"},
{"repo-archive", "storage.repo-archive"},
{"packages", "storage.packages"},
// the actions sections are not included here because they were experimental at the time
}
func v1TOv5_0_1Included(e db.Engine, dbVersion int64, cfg setting.ConfigProvider) error {
//
// When upgrading from Forgejo > v5 or Gitea > v1.20, no sanity check is necessary
//
if dbVersion > ForgejoV5DatabaseVersion {
return nil
}
//
// When upgrading from a Forgejo point version >= v5.0.1, no sanity
// check is necessary
//
// When upgrading from a Gitea >= v1.20 the sanitiy checks will
// always be done They are necessary for Gitea [v1.20.0..v1.20.2]
// but not for [v1.20.3..] but there is no way to know which point
// release was running prior to the upgrade. This may require the
// Gitea admin to update their app.ini although it is not necessary
// but will have no other consequence.
//
previousServerVersion, err := semver.GetVersionWithEngine(e)
if err != nil {
return err
}
upper, err := version.NewVersion("v5.0.1")
if err != nil {
return err
}
if previousServerVersion.GreaterThan(upper) {
return nil
}
//
// Sanity checks
//
originalCfg, err := cfg.PrepareSaving()
if err != nil {
return err
}
messages := make([]string, 0, 10)
for _, c := range v1TOv5_0_1IncludedStorageSections {
section, _ := originalCfg.GetSection(c.section)
if section == nil {
continue
}
storageSection, _ := originalCfg.GetSection(c.storageSection)
if storageSection == nil {
continue
}
messages = append(messages, fmt.Sprintf("[%s] and [%s] may conflict with each other", c.section, c.storageSection))
}
if originalCfg.Section("storage").HasKey("PATH") {
messages = append(messages, "[storage].PATH is set and may create storage issues")
}
if len(messages) > 0 {
return fatal(fmt.Errorf("%s\nThese issues need to be manually fixed in the app.ini file at %s. Please read https://forgejo.org/2023-08-release-v1-20-3-0/ for instructions", strings.Join(messages, "\n"), cfg.GetFile()))
}
return nil
}