fix(setting): resolve relative APP_TEMP_PATH against APP_DATA_PATH (#40527)

A relative `APP_TEMP_PATH` was resolved against the process working
directory, which differs between Gitea processes. `gitea hook` runs from
the bare repository, so its startup check failed and every push was
rejected. It now resolves against `APP_DATA_PATH`, like the other data
paths.

Fixes:
https://github.com/go-gitea/gitea/pull/40448#discussion_r4689040364
Docs: https://gitea.com/gitea/docs/pulls/661

Assisted-by: Claude Code:claude-opus-5-5

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwindandwxiaoguang authored and GitHub committed 2026-11-28 07:22:03 +00:00
1 parent 5be2141de0
commit 325d40903b
4 files changed
+20 -2

No files matched your search

+3 -1
View File
@@ -290,7 +290,9 @@
;; Default path for App data
;APP_DATA_PATH = data ; relative paths will be made absolute with _`AppWorkPath`_
;;
;; Base path for App's temp files, leave empty to use the managed tmp directory in APP_DATA_PATH
;; Base path for temp files, relative to APP_DATA_PATH, leave empty to use the default managed tmp directory.
;; * For NFS instances: prefer an absolute local path for better writing performance.
;; * For HA and load-balanced instances: use a shared directory for all instances.
;APP_TEMP_PATH =
;;
;; Enable gzip compression for runtime-generated content, static resources excluded
+5 -1
View File
@@ -211,9 +211,13 @@ func MockBuiltinPaths(workPath, customPath, customConf string) func() {
// AppDataTempDir returns a managed temporary directory for the application data.
// Using empty sub will get the managed base temp directory, and it's safe to delete it.
// Gitea only creates subdirectories under it, but not the APP_TEMP_PATH directory itself.
// Gitea only creates subdirectories under it, but not the APP_TEMP_PATH directory itself,
// so all temp directories and files can be deleted safely, Gitea also cleans up them when it starts up.
// * When APP_TEMP_PATH="/tmp": the managed temp directory is "/tmp/gitea-tmp"
// * When APP_TEMP_PATH is not set: the managed temp directory is "/{APP_DATA_PATH}/tmp"
// In some cases, the temp directory should be carefully chosen:
// * For NFS instances: prefer an absolute local path, because NFS may have issues with file writing performance.
// * For HA and load-balanced instances: use a shared directory, temp files may be needed by different requests (e.g.: package uploading)
func AppDataTempDir(sub string) *tempdir.TempDir {
if appTempPathInternal != "" {
return tempdir.New(appTempPathInternal, "gitea-tmp/"+sub)
+9
View File
@@ -115,6 +115,15 @@ func TestInitWorkPathAndCommonConfig(t *testing.T) {
assert.True(t, AppWorkPathMismatch)
})
t.Run("AppTempPathRelativeToAppDataPath", func(t *testing.T) {
iniTempPath := fp(tmpDir, "app-temppath.ini")
_ = os.WriteFile(iniTempPath, []byte("[server]\nAPP_TEMP_PATH=temp"), 0o644)
_ = os.MkdirAll(fp(dirFoo, "data/temp"), 0o755)
testInit(dirFoo, "", "")
InitWorkPathAndCommonConfig(envVars{}.Getenv, ArgWorkPathAndCustomConf{CustomConf: iniTempPath})
assert.Equal(t, fp(dirFoo, "data/temp/gitea-tmp"), AppDataTempDir("").JoinPath())
})
t.Run("Builtin", func(t *testing.T) {
testInit(dirFoo, dirBar, dirXxx)
InitWorkPathAndCommonConfig(envVars{}.Getenv, ArgWorkPathAndCustomConf{})
+3
View File
@@ -265,6 +265,9 @@ func loadServerFrom(rootCfg ConfigProvider) {
appTempPathInternal = sec.Key("APP_TEMP_PATH").String()
if appTempPathInternal != "" {
if !filepath.IsAbs(appTempPathInternal) {
appTempPathInternal = filepath.Join(AppDataPath, appTempPathInternal)
}
if _, err := os.Stat(appTempPathInternal); err != nil {
log.Fatal("APP_TEMP_PATH %q is not accessible: %v", appTempPathInternal, err)
}