Move all temporary directories under gitea and cleanup it when Gitea start

This commit is contained in:
Lunny Xiao 2024-10-27 17:30:20 -07:00
parent fafd7b73ba
commit 30621ae207
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
6 changed files with 14 additions and 2 deletions

View File

@ -153,6 +153,7 @@ func serveInstall(ctx *cli.Context) error {
func serveInstalled(ctx *cli.Context) error {
setting.InitCfgProvider(setting.CustomConf)
setting.LoadCommonSettings()
setting.CleanUpTempDirs()
setting.MustInstalled()
showWebStartupMessage("Prepare to run web server")

View File

@ -60,6 +60,7 @@ func InitSettings() {
}
setting.InitCfgProvider(setting.CustomConf)
setting.LoadCommonSettings()
setting.CleanUpTempDirs()
if err := setting.PrepareAppDataPath(); err != nil {
log.Fatal("Can not prepare APP_DATA_PATH: %v", err)

View File

@ -55,6 +55,7 @@ func TestVerifyTimeLimitCode(t *testing.T) {
JWT_SECRET = %s
`, secret))
setting.LoadCommonSettings()
setting.CleanUpTempDirs()
}
initGeneralSecret("KZb_QLUd4fYVyxetjxC4eZkrBgWM2SndOOWDNtgUUko")

View File

@ -3,7 +3,10 @@
package setting
import "os"
import (
"os"
"path/filepath"
)
// Global settings
var (
@ -21,5 +24,9 @@ var (
// TempDir returns the OS temp directory
func TempDir() string {
return os.TempDir()
return filepath.Join(os.TempDir(), "gitea")
}
func CleanUpTempDirs() {
_ = os.RemoveAll(TempDir())
}

View File

@ -91,6 +91,7 @@ func (s *stringWithDefault) Set(v string) {
func InitWorkPathAndCommonConfig(getEnvFn func(name string) string, args ArgWorkPathAndCustomConf) {
InitWorkPathAndCfgProvider(getEnvFn, args)
LoadCommonSettings()
CleanUpTempDirs()
}
// InitWorkPathAndCfgProvider will set AppWorkPath, CustomPath and CustomConf, init default config provider by CustomConf

View File

@ -535,6 +535,7 @@ func SubmitInstall(ctx *context.Context) {
// Reload settings (and re-initialize database connection)
setting.InitCfgProvider(setting.CustomConf)
setting.LoadCommonSettings()
setting.CleanUpTempDirs()
setting.MustInstalled()
setting.LoadDBSetting()
if err := common.InitDBEngine(ctx); err != nil {