Skip to content

Commit af93c23

Browse files
wxiaoguangGiteaBot
authored andcommitted
Do not allow different storage configurations to point to the same directory (go-gitea#30169)
Replace go-gitea#29171
1 parent 9d38c4d commit af93c23

File tree

12 files changed

+75
-47
lines changed

12 files changed

+75
-47
lines changed

modules/setting/indexer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func loadIndexerFrom(rootCfg ConfigProvider) {
5858
if !filepath.IsAbs(Indexer.IssuePath) {
5959
Indexer.IssuePath = filepath.ToSlash(filepath.Join(AppWorkPath, Indexer.IssuePath))
6060
}
61-
fatalDuplicatedPath("issue_indexer", Indexer.IssuePath)
61+
checkOverlappedPath("indexer.ISSUE_INDEXER_PATH", Indexer.IssuePath)
6262
} else {
6363
Indexer.IssueConnStr = sec.Key("ISSUE_INDEXER_CONN_STR").MustString(Indexer.IssueConnStr)
6464
if Indexer.IssueType == "meilisearch" {

modules/setting/path.go

-4
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,8 @@ func init() {
6666
AppWorkPath = filepath.Dir(AppPath)
6767
}
6868

69-
fatalDuplicatedPath("app_work_path", AppWorkPath)
70-
7169
appWorkPathBuiltin = AppWorkPath
7270
customPathBuiltin = CustomPath
73-
74-
fatalDuplicatedPath("custom_path", CustomPath)
7571
customConfBuiltin = CustomConf
7672
}
7773

modules/setting/repository.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func loadRepositoryFrom(rootCfg ConfigProvider) {
286286
RepoRootPath = filepath.Clean(RepoRootPath)
287287
}
288288

289-
fatalDuplicatedPath("repository.ROOT", RepoRootPath)
289+
checkOverlappedPath("repository.ROOT", RepoRootPath)
290290

291291
defaultDetectedCharsetsOrder := make([]string, 0, len(Repository.DetectedCharsetsOrder))
292292
for _, charset := range Repository.DetectedCharsetsOrder {

modules/setting/server.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,14 @@ func loadServerFrom(rootCfg ConfigProvider) {
324324
if !filepath.IsAbs(AppDataPath) {
325325
AppDataPath = filepath.ToSlash(filepath.Join(AppWorkPath, AppDataPath))
326326
}
327-
fatalDuplicatedPath("app_data_path", AppDataPath)
328327

329328
EnableGzip = sec.Key("ENABLE_GZIP").MustBool()
330329
EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false)
331330
PprofDataPath = sec.Key("PPROF_DATA_PATH").MustString(filepath.Join(AppWorkPath, "data/tmp/pprof"))
332331
if !filepath.IsAbs(PprofDataPath) {
333332
PprofDataPath = filepath.Join(AppWorkPath, PprofDataPath)
334333
}
335-
fatalDuplicatedPath("pprof_data_path", PprofDataPath)
334+
checkOverlappedPath("server.PPROF_DATA_PATH", PprofDataPath)
336335

337336
landingPage := sec.Key("LANDING_PAGE").MustString("home")
338337
switch landingPage {

modules/setting/session.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func loadSessionFrom(rootCfg ConfigProvider) {
4646
SessionConfig.ProviderConfig = strings.Trim(sec.Key("PROVIDER_CONFIG").MustString(filepath.Join(AppDataPath, "sessions")), "\" ")
4747
if SessionConfig.Provider == "file" && !filepath.IsAbs(SessionConfig.ProviderConfig) {
4848
SessionConfig.ProviderConfig = filepath.Join(AppWorkPath, SessionConfig.ProviderConfig)
49-
fatalDuplicatedPath("session", SessionConfig.ProviderConfig)
49+
checkOverlappedPath("session.PROVIDER_CONFIG", SessionConfig.ProviderConfig)
5050
}
5151
SessionConfig.CookieName = sec.Key("COOKIE_NAME").MustString("i_like_gitea")
5252
SessionConfig.CookiePath = AppSubURL

modules/setting/setting.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,14 @@ func LoadSettingsForInstall() {
230230
loadMailerFrom(CfgProvider)
231231
}
232232

233-
var uniquePaths = make(map[string]string)
233+
var configuredPaths = make(map[string]string)
234234

235-
func fatalDuplicatedPath(name, p string) {
236-
if targetName, ok := uniquePaths[p]; ok && targetName != name {
237-
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)
235+
func checkOverlappedPath(name, path string) {
236+
// TODO: some paths shouldn't overlap (storage.xxx.path), while some could (data path is the base path for storage path)
237+
if targetName, ok := configuredPaths[path]; ok && targetName != name {
238+
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)
239+
log.Error("%s", msg)
240+
DeprecatedWarnings = append(DeprecatedWarnings, msg)
238241
}
239-
uniquePaths[p] = name
242+
configuredPaths[path] = name
240243
}

modules/setting/storage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func getStorageForLocal(targetSec, overrideSec ConfigSection, tp targetSecType,
240240
}
241241
}
242242

243-
fatalDuplicatedPath("storage."+name, storage.Path)
243+
checkOverlappedPath("storage."+name+".PATH", storage.Path)
244244

245245
return &storage, nil
246246
}

options/locale/locale_en-US.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -2775,6 +2775,7 @@ teams.invite.by = Invited by %s
27752775
teams.invite.description = Please click the button below to join the team.
27762776

27772777
[admin]
2778+
maintenance = Maintenance
27782779
dashboard = Dashboard
27792780
self_check = Self Check
27802781
identity_access = Identity & Access
@@ -2798,7 +2799,7 @@ settings = Admin Settings
27982799

27992800
dashboard.new_version_hint = Gitea %s is now available, you are running %s. Check <a target="_blank" rel="noreferrer" href="https://blog.gitea.io">the blog</a> for more details.
28002801
dashboard.statistic = Summary
2801-
dashboard.operations = Maintenance Operations
2802+
dashboard.maintenance_operations = Maintenance Operations
28022803
dashboard.system_status = System Status
28032804
dashboard.operation_name = Operation Name
28042805
dashboard.operation_switch = Switch
@@ -3305,6 +3306,7 @@ notices.op = Op.
33053306
notices.delete_success = The system notices have been deleted.
33063307

33073308
self_check.no_problem_found = No problem found yet.
3309+
self_check.startup_warnings = Startup warnings:
33083310
self_check.database_collation_mismatch = Expect database to use collation: %s
33093311
self_check.database_collation_case_insensitive = Database is using a collation %s, which is an insensitive collation. Although Gitea could work with it, there might be some rare cases which don't work as expected.
33103312
self_check.database_inconsistent_collation_columns = Database is using collation %s, but these columns are using mismatched collations. It might cause some unexpected problems.

routers/web/admin/admin.go

+8
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ func DashboardPost(ctx *context.Context) {
190190

191191
func SelfCheck(ctx *context.Context) {
192192
ctx.Data["PageIsAdminSelfCheck"] = true
193+
194+
ctx.Data["DeprecatedWarnings"] = setting.DeprecatedWarnings
195+
if len(setting.DeprecatedWarnings) == 0 && !setting.IsProd {
196+
if time.Now().Unix()%2 == 0 {
197+
ctx.Data["DeprecatedWarnings"] = []string{"This is a test warning message in dev mode"}
198+
}
199+
}
200+
193201
r, err := db.CheckCollationsDefaultEngine()
194202
if err != nil {
195203
ctx.Flash.Error(fmt.Sprintf("CheckCollationsDefaultEngine: %v", err), true)

templates/admin/dashboard.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</div>
77
{{end}}
88
<h4 class="ui top attached header">
9-
{{ctx.Locale.Tr "admin.dashboard.operations"}}
9+
{{ctx.Locale.Tr "admin.dashboard.maintenance_operations"}}
1010
</h4>
1111
<div class="ui attached table segment">
1212
<form method="post" action="{{AppSubUrl}}/admin">

templates/admin/navbar.tmpl

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<div class="flex-container-nav">
22
<div class="ui fluid vertical menu">
33
<div class="header item">{{ctx.Locale.Tr "admin.settings"}}</div>
4-
<a class="{{if .PageIsAdminDashboard}}active {{end}}item" href="{{AppSubUrl}}/admin">
5-
{{ctx.Locale.Tr "admin.dashboard"}}
6-
</a>
7-
<a class="{{if .PageIsAdminSelfCheck}}active {{end}}item" href="{{AppSubUrl}}/admin/self_check">
8-
{{ctx.Locale.Tr "admin.self_check"}}
9-
</a>
4+
5+
<details class="item toggleable-item" {{if or .PageIsAdminDashboard .PageIsAdminSelfCheck}}open{{end}}>
6+
<summary>{{ctx.Locale.Tr "admin.maintenance"}}</summary>
7+
<div class="menu">
8+
<a class="{{if .PageIsAdminDashboard}}active {{end}}item" href="{{AppSubUrl}}/admin">
9+
{{ctx.Locale.Tr "admin.dashboard"}}
10+
</a>
11+
<a class="{{if .PageIsAdminSelfCheck}}active {{end}}item" href="{{AppSubUrl}}/admin/self_check">
12+
{{ctx.Locale.Tr "admin.self_check"}}
13+
</a>
14+
</div>
15+
</details>
1016
<details class="item toggleable-item" {{if or .PageIsAdminUsers .PageIsAdminEmails .PageIsAdminOrganizations .PageIsAdminAuthentications}}open{{end}}>
1117
<summary>{{ctx.Locale.Tr "admin.identity_access"}}</summary>
1218
<div class="menu">

templates/admin/self_check.tmpl

+38-24
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,47 @@
44
<h4 class="ui top attached header">
55
{{ctx.Locale.Tr "admin.self_check"}}
66
</h4>
7+
8+
{{if .DeprecatedWarnings}}
79
<div class="ui attached segment">
8-
{{if .DatabaseCheckHasProblems}}
9-
{{if .DatabaseType.IsMySQL}}
10-
<div class="tw-p-2">{{ctx.Locale.Tr "admin.self_check.database_fix_mysql"}}</div>
11-
{{else if .DatabaseType.IsMSSQL}}
12-
<div class="tw-p-2">{{ctx.Locale.Tr "admin.self_check.database_fix_mssql"}}</div>
13-
{{end}}
14-
{{if .DatabaseCheckCollationMismatch}}
15-
<div class="ui red message">{{ctx.Locale.Tr "admin.self_check.database_collation_mismatch" .DatabaseCheckResult.ExpectedCollation}}</div>
16-
{{end}}
17-
{{if .DatabaseCheckCollationCaseInsensitive}}
18-
<div class="ui warning message">{{ctx.Locale.Tr "admin.self_check.database_collation_case_insensitive" .DatabaseCheckResult.DatabaseCollation}}</div>
19-
{{end}}
20-
{{if .DatabaseCheckInconsistentCollationColumns}}
21-
<div class="ui red message">
22-
{{ctx.Locale.Tr "admin.self_check.database_inconsistent_collation_columns" .DatabaseCheckResult.DatabaseCollation}}
23-
<ul class="tw-w-full">
24-
{{range .DatabaseCheckInconsistentCollationColumns}}
25-
<li>{{.}}</li>
26-
{{end}}
27-
</ul>
28-
</div>
29-
{{end}}
30-
{{else}}
31-
<div class="tw-p-2">{{ctx.Locale.Tr "admin.self_check.no_problem_found"}}</div>
10+
<div class="ui warning message">
11+
<div>{{ctx.Locale.Tr "admin.self_check.startup_warnings"}}</div>
12+
<ul class="tw-w-full">{{range .DeprecatedWarnings}}<li>{{.}}</li>{{end}}</ul>
13+
</div>
14+
</div>
15+
{{end}}
16+
17+
{{if .DatabaseCheckHasProblems}}
18+
<div class="ui attached segment">
19+
{{if .DatabaseType.IsMySQL}}
20+
<div class="tw-p-2">{{ctx.Locale.Tr "admin.self_check.database_fix_mysql"}}</div>
21+
{{else if .DatabaseType.IsMSSQL}}
22+
<div class="tw-p-2">{{ctx.Locale.Tr "admin.self_check.database_fix_mssql"}}</div>
23+
{{end}}
24+
{{if .DatabaseCheckCollationMismatch}}
25+
<div class="ui red message">{{ctx.Locale.Tr "admin.self_check.database_collation_mismatch" .DatabaseCheckResult.ExpectedCollation}}</div>
3226
{{end}}
27+
{{if .DatabaseCheckCollationCaseInsensitive}}
28+
<div class="ui warning message">{{ctx.Locale.Tr "admin.self_check.database_collation_case_insensitive" .DatabaseCheckResult.DatabaseCollation}}</div>
29+
{{end}}
30+
{{if .DatabaseCheckInconsistentCollationColumns}}
31+
<div class="ui red message">
32+
{{ctx.Locale.Tr "admin.self_check.database_inconsistent_collation_columns" .DatabaseCheckResult.DatabaseCollation}}
33+
<ul class="tw-w-full">
34+
{{range .DatabaseCheckInconsistentCollationColumns}}
35+
<li>{{.}}</li>
36+
{{end}}
37+
</ul>
38+
</div>
39+
{{end}}
40+
</div>
41+
{{end}}
42+
43+
{{if and (not .DeprecatedWarnings) (not .DatabaseCheckHasProblems)}}
44+
<div class="ui attached segment">
45+
{{ctx.Locale.Tr "admin.self_check.no_problem_found"}}
3346
</div>
47+
{{end}}
3448
</div>
3549

3650
{{template "admin/layout_footer" .}}

0 commit comments

Comments
 (0)