Skip to content

Commit cb81214

Browse files
committed
create temp root directory when startup
1 parent 30621ae commit cb81214

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

modules/setting/global.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
package setting
55

66
import (
7+
"log"
78
"os"
89
"path/filepath"
10+
"sync"
911
)
1012

1113
// Global settings
@@ -20,11 +22,19 @@ var (
2022

2123
// AppName is the Application name, used in the page title. ini: "APP_NAME"
2224
AppName string
25+
26+
createTempOnce sync.Once
2327
)
2428

2529
// TempDir returns the OS temp directory
2630
func TempDir() string {
27-
return filepath.Join(os.TempDir(), "gitea")
31+
tempDir := filepath.Join(os.TempDir(), "gitea")
32+
createTempOnce.Do(func() {
33+
if err := os.MkdirAll(tempDir, os.ModePerm); err != nil {
34+
log.Fatalf("Failed to create temp directory %s: %v", tempDir, err)
35+
}
36+
})
37+
return tempDir
2838
}
2939

3040
func CleanUpTempDirs() {

0 commit comments

Comments
 (0)