Skip to content

Commit

Permalink
Add optional doctor storage init (#30330)
Browse files Browse the repository at this point in the history
Add optional storage init to doctor
  • Loading branch information
viceice authored Apr 8, 2024
1 parent d872ce0 commit ff7aab4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions services/doctor/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
)

// Check represents a Doctor check
Expand All @@ -25,6 +26,7 @@ type Check struct {
AbortIfFailed bool
SkipDatabaseInitialization bool
Priority int
InitStorage bool
}

func initDBSkipLogger(ctx context.Context) error {
Expand Down Expand Up @@ -84,6 +86,7 @@ func RunChecks(ctx context.Context, colorize, autofix bool, checks []*Check) err
logger := log.BaseLoggerToGeneralLogger(&doctorCheckLogger{colorize: colorize})
loggerStep := log.BaseLoggerToGeneralLogger(&doctorCheckStepLogger{colorize: colorize})
dbIsInit := false
storageIsInit := false
for i, check := range checks {
if !dbIsInit && !check.SkipDatabaseInitialization {
// Only open database after the most basic configuration check
Expand All @@ -94,6 +97,14 @@ func RunChecks(ctx context.Context, colorize, autofix bool, checks []*Check) err
}
dbIsInit = true
}
if !storageIsInit && check.InitStorage {
if err := storage.Init(); err != nil {
logger.Error("Error whilst initializing the storage: %v", err)
logger.Error("Check if you are using the right config file. You can use a --config directive to specify one.")
return nil
}
storageIsInit = true
}
logger.Info("\n[%d] %s", i+1, check.Title)
if err := check.Run(ctx, loggerStep, autofix); err != nil {
if check.AbortIfFailed {
Expand Down

0 comments on commit ff7aab4

Please sign in to comment.