create temp root directory when startup

This commit is contained in:
Lunny Xiao 2024-10-27 17:58:07 -07:00
parent 30621ae207
commit cb812144b5
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A

View File

@ -4,8 +4,10 @@
package setting
import (
"log"
"os"
"path/filepath"
"sync"
)
// Global settings
@ -20,11 +22,19 @@ var (
// AppName is the Application name, used in the page title. ini: "APP_NAME"
AppName string
createTempOnce sync.Once
)
// TempDir returns the OS temp directory
func TempDir() string {
return filepath.Join(os.TempDir(), "gitea")
tempDir := filepath.Join(os.TempDir(), "gitea")
createTempOnce.Do(func() {
if err := os.MkdirAll(tempDir, os.ModePerm); err != nil {
log.Fatalf("Failed to create temp directory %s: %v", tempDir, err)
}
})
return tempDir
}
func CleanUpTempDirs() {