Skip to content

Commit 30621ae

Browse files
committed
Move all temporary directories under gitea and cleanup it when Gitea start
1 parent fafd7b7 commit 30621ae

File tree

6 files changed

+14
-2
lines changed

6 files changed

+14
-2
lines changed

cmd/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func serveInstall(ctx *cli.Context) error {
153153
func serveInstalled(ctx *cli.Context) error {
154154
setting.InitCfgProvider(setting.CustomConf)
155155
setting.LoadCommonSettings()
156+
setting.CleanUpTempDirs()
156157
setting.MustInstalled()
157158

158159
showWebStartupMessage("Prepare to run web server")

models/unittest/testdb.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func InitSettings() {
6060
}
6161
setting.InitCfgProvider(setting.CustomConf)
6262
setting.LoadCommonSettings()
63+
setting.CleanUpTempDirs()
6364

6465
if err := setting.PrepareAppDataPath(); err != nil {
6566
log.Fatal("Can not prepare APP_DATA_PATH: %v", err)

modules/base/tool_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestVerifyTimeLimitCode(t *testing.T) {
5555
JWT_SECRET = %s
5656
`, secret))
5757
setting.LoadCommonSettings()
58+
setting.CleanUpTempDirs()
5859
}
5960

6061
initGeneralSecret("KZb_QLUd4fYVyxetjxC4eZkrBgWM2SndOOWDNtgUUko")

modules/setting/global.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
package setting
55

6-
import "os"
6+
import (
7+
"os"
8+
"path/filepath"
9+
)
710

811
// Global settings
912
var (
@@ -21,5 +24,9 @@ var (
2124

2225
// TempDir returns the OS temp directory
2326
func TempDir() string {
24-
return os.TempDir()
27+
return filepath.Join(os.TempDir(), "gitea")
28+
}
29+
30+
func CleanUpTempDirs() {
31+
_ = os.RemoveAll(TempDir())
2532
}

modules/setting/path.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (s *stringWithDefault) Set(v string) {
9191
func InitWorkPathAndCommonConfig(getEnvFn func(name string) string, args ArgWorkPathAndCustomConf) {
9292
InitWorkPathAndCfgProvider(getEnvFn, args)
9393
LoadCommonSettings()
94+
CleanUpTempDirs()
9495
}
9596

9697
// InitWorkPathAndCfgProvider will set AppWorkPath, CustomPath and CustomConf, init default config provider by CustomConf

routers/install/install.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ func SubmitInstall(ctx *context.Context) {
535535
// Reload settings (and re-initialize database connection)
536536
setting.InitCfgProvider(setting.CustomConf)
537537
setting.LoadCommonSettings()
538+
setting.CleanUpTempDirs()
538539
setting.MustInstalled()
539540
setting.LoadDBSetting()
540541
if err := common.InitDBEngine(ctx); err != nil {

0 commit comments

Comments
 (0)