1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Do not allow different storage configurations to point to the same directory (#30169) (#30204)

Backport #30169 by wxiaoguang

Replace #29171

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot
2024-03-31 11:29:51 +08:00
committed by GitHub
parent 9d38c4d60e
commit cd117863f3
12 changed files with 75 additions and 47 deletions

View File

@@ -58,7 +58,7 @@ func loadIndexerFrom(rootCfg ConfigProvider) {
if !filepath.IsAbs(Indexer.IssuePath) {
Indexer.IssuePath = filepath.ToSlash(filepath.Join(AppWorkPath, Indexer.IssuePath))
}
fatalDuplicatedPath("issue_indexer", Indexer.IssuePath)
checkOverlappedPath("indexer.ISSUE_INDEXER_PATH", Indexer.IssuePath)
} else {
Indexer.IssueConnStr = sec.Key("ISSUE_INDEXER_CONN_STR").MustString(Indexer.IssueConnStr)
if Indexer.IssueType == "meilisearch" {

View File

@@ -66,12 +66,8 @@ func init() {
AppWorkPath = filepath.Dir(AppPath)
}
fatalDuplicatedPath("app_work_path", AppWorkPath)
appWorkPathBuiltin = AppWorkPath
customPathBuiltin = CustomPath
fatalDuplicatedPath("custom_path", CustomPath)
customConfBuiltin = CustomConf
}

View File

@@ -286,7 +286,7 @@ func loadRepositoryFrom(rootCfg ConfigProvider) {
RepoRootPath = filepath.Clean(RepoRootPath)
}
fatalDuplicatedPath("repository.ROOT", RepoRootPath)
checkOverlappedPath("repository.ROOT", RepoRootPath)
defaultDetectedCharsetsOrder := make([]string, 0, len(Repository.DetectedCharsetsOrder))
for _, charset := range Repository.DetectedCharsetsOrder {

View File

@@ -324,7 +324,6 @@ func loadServerFrom(rootCfg ConfigProvider) {
if !filepath.IsAbs(AppDataPath) {
AppDataPath = filepath.ToSlash(filepath.Join(AppWorkPath, AppDataPath))
}
fatalDuplicatedPath("app_data_path", AppDataPath)
EnableGzip = sec.Key("ENABLE_GZIP").MustBool()
EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false)
@@ -332,7 +331,7 @@ func loadServerFrom(rootCfg ConfigProvider) {
if !filepath.IsAbs(PprofDataPath) {
PprofDataPath = filepath.Join(AppWorkPath, PprofDataPath)
}
fatalDuplicatedPath("pprof_data_path", PprofDataPath)
checkOverlappedPath("server.PPROF_DATA_PATH", PprofDataPath)
landingPage := sec.Key("LANDING_PAGE").MustString("home")
switch landingPage {

View File

@@ -46,7 +46,7 @@ func loadSessionFrom(rootCfg ConfigProvider) {
SessionConfig.ProviderConfig = strings.Trim(sec.Key("PROVIDER_CONFIG").MustString(filepath.Join(AppDataPath, "sessions")), "\" ")
if SessionConfig.Provider == "file" && !filepath.IsAbs(SessionConfig.ProviderConfig) {
SessionConfig.ProviderConfig = filepath.Join(AppWorkPath, SessionConfig.ProviderConfig)
fatalDuplicatedPath("session", SessionConfig.ProviderConfig)
checkOverlappedPath("session.PROVIDER_CONFIG", SessionConfig.ProviderConfig)
}
SessionConfig.CookieName = sec.Key("COOKIE_NAME").MustString("i_like_gitea")
SessionConfig.CookiePath = AppSubURL

View File

@@ -230,11 +230,14 @@ func LoadSettingsForInstall() {
loadMailerFrom(CfgProvider)
}
var uniquePaths = make(map[string]string)
var configuredPaths = make(map[string]string)
func fatalDuplicatedPath(name, p string) {
if targetName, ok := uniquePaths[p]; ok && targetName != name {
log.Fatal("storage path %q is being used by %q and %q and all storage paths must be unique to prevent data loss.", p, targetName, name)
func checkOverlappedPath(name, path string) {
// TODO: some paths shouldn't overlap (storage.xxx.path), while some could (data path is the base path for storage path)
if targetName, ok := configuredPaths[path]; ok && targetName != name {
msg := fmt.Sprintf("Configured path %q is used by %q and %q at the same time. The paths must be unique to prevent data loss.", path, targetName, name)
log.Error("%s", msg)
DeprecatedWarnings = append(DeprecatedWarnings, msg)
}
uniquePaths[p] = name
configuredPaths[path] = name
}

View File

@@ -240,7 +240,7 @@ func getStorageForLocal(targetSec, overrideSec ConfigSection, tp targetSecType,
}
}
fatalDuplicatedPath("storage."+name, storage.Path)
checkOverlappedPath("storage."+name+".PATH", storage.Path)
return &storage, nil
}