Skip to content

Commit d16b3e8

Browse files
committed
fix AppWorkPath/AppDataPath usages
1 parent 13bc12e commit d16b3e8

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

cmd/web_acme.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ func runACME(listenAddr string, m http.Handler) error {
6464
log.Warn("Failed to parse CA Root certificate, using default CA trust: %v", err)
6565
}
6666
}
67-
// FIXME: this path is not right, it uses "AppWorkPath" incorrectly, and writes the data into "AppWorkPath/https"
68-
// Ideally it should migrate to AppDataPath write to "AppDataPath/https"
69-
// And one more thing, no idea why we should set the global default variables here
67+
// No idea why we should set the global default variables here
7068
// But it seems that the current ACME code needs these global variables to make renew work.
7169
// Otherwise, "renew" will use incorrect storage path
7270
oldDefaultACME := certmagic.DefaultACME

custom/conf/app.example.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ RUN_USER = ; git
263263
;; Can be left blank to initialize at first run and use the cached value
264264
;ACME_EMAIL =
265265
;;
266-
;; ACME live directory (not to be confused with ACME directory URL: ACME_URL)
266+
;; ACME live directory (not to be confused with ACME directory URL: ACME_URL), relative to _`AppDataPath`_
267267
;; (Refer to caddy's ACME manager https://github.com/caddyserver/certmagic)
268268
;ACME_DIRECTORY = https
269269
;;
@@ -301,7 +301,7 @@ RUN_USER = ; git
301301
;ENABLE_PPROF = false
302302
;;
303303
;; PPROF_DATA_PATH, use an absolute path when you start gitea as service
304-
;PPROF_DATA_PATH = data/tmp/pprof ; Path is relative to _`AppWorkPath`_
304+
;PPROF_DATA_PATH = tmp/pprof ; Path is relative to _`AppDataPath`_
305305
;;
306306
;; Landing page, can be "home", "explore", "organizations", "login", or any URL such as "/org/repo" or even "https://anotherwebsite.com"
307307
;; The "login" choice is not a security measure but just a UI flow change, use REQUIRE_SIGNIN_VIEW to force users to log in.

docker/root/etc/templates/app.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ DISABLE_SSH = $DISABLE_SSH
2020
SSH_PORT = $SSH_PORT
2121
SSH_LISTEN_PORT = $SSH_LISTEN_PORT
2222
LFS_START_SERVER = $LFS_START_SERVER
23-
ACME_DIRECTORY = /data/gitea/acme
2423

2524
[database]
2625
PATH = /data/gitea/gitea.db

docker/rootless/etc/templates/app.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ SSH_PORT = $SSH_PORT
2323
SSH_LISTEN_PORT = $SSH_LISTEN_PORT
2424
BUILTIN_SSH_SERVER_USER = $RUN_USER
2525
LFS_START_SERVER = $LFS_START_SERVER
26-
ACME_DIRECTORY = $GITEA_WORK_DIR/acme
2726

2827
[database]
2928
PATH = $GITEA_WORK_DIR/data/gitea.db

modules/setting/path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
AppPath string
2020

2121
// AppWorkPath is the "working directory" of Gitea. It maps to the: WORK_PATH in app.ini, "--work-path" flag, environment variable GITEA_WORK_DIR.
22-
// If that is not set it is the default set here by the linker or failing that the directory of AppPath.
22+
// If that is not set it is the default set here by the linker or falling to AppPath (which is not writable in some cases, for example: "/usr/local/bin/gitea").
2323
// It is used as the base path for several other paths.
2424
AppWorkPath string
2525
CustomPath string // Custom directory path. Env: GITEA_CUSTOM

modules/setting/server.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,20 @@ func MakeAbsoluteAssetURL(appURL, staticURLPrefix string) string {
182182
}
183183

184184
func loadServerFrom(rootCfg ConfigProvider) {
185-
sec := rootCfg.Section("server")
186185
AppName = rootCfg.Section("").Key("APP_NAME").MustString("Gitea: Git with a cup of tea")
187186

187+
sec := rootCfg.Section("server")
188+
AppDataPath = sec.Key("APP_DATA_PATH").MustString(filepath.Join(AppWorkPath, "data"))
189+
if !filepath.IsAbs(AppDataPath) {
190+
AppDataPath = filepath.ToSlash(filepath.Join(AppWorkPath, AppDataPath))
191+
}
192+
if IsInTesting && HasInstallLock(rootCfg) {
193+
// FIXME: in testing, the "app data" directory is not correctly initialized before loading settings
194+
if _, err := os.Stat(AppDataPath); err != nil {
195+
_ = os.MkdirAll(AppDataPath, os.ModePerm)
196+
}
197+
}
198+
188199
Domain = sec.Key("DOMAIN").MustString("localhost")
189200
HTTPAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0")
190201
HTTPPort = sec.Key("HTTP_PORT").MustString("3000")
@@ -228,7 +239,9 @@ func loadServerFrom(rootCfg ConfigProvider) {
228239
deprecatedSetting(rootCfg, "server", "LETSENCRYPT_DIRECTORY", "server", "ACME_DIRECTORY", "v1.19.0")
229240
AcmeLiveDirectory = sec.Key("LETSENCRYPT_DIRECTORY").MustString("https")
230241
}
231-
242+
if !filepath.IsAbs(AcmeLiveDirectory) {
243+
AcmeLiveDirectory = filepath.Join(AppDataPath, AcmeLiveDirectory)
244+
}
232245
if sec.HasKey("ACME_EMAIL") {
233246
AcmeEmail = sec.Key("ACME_EMAIL").MustString("")
234247
} else {
@@ -272,7 +285,7 @@ func loadServerFrom(rootCfg ConfigProvider) {
272285

273286
UnixSocketPermission = uint32(UnixSocketPermissionParsed)
274287
if !filepath.IsAbs(HTTPAddr) {
275-
HTTPAddr = filepath.Join(AppWorkPath, HTTPAddr)
288+
HTTPAddr = filepath.Join(AppWorkPath, HTTPAddr) // FIXME: it shouldn't default to AppWorkPath (which is not writable in some cases)
276289
}
277290
default:
278291
log.Fatal("Invalid PROTOCOL %q", protocolCfg)
@@ -355,16 +368,6 @@ func loadServerFrom(rootCfg ConfigProvider) {
355368
}
356369
StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(StaticRootPath)
357370
StaticCacheTime = sec.Key("STATIC_CACHE_TIME").MustDuration(6 * time.Hour)
358-
AppDataPath = sec.Key("APP_DATA_PATH").MustString(filepath.Join(AppWorkPath, "data"))
359-
if !filepath.IsAbs(AppDataPath) {
360-
AppDataPath = filepath.ToSlash(filepath.Join(AppWorkPath, AppDataPath))
361-
}
362-
if IsInTesting && HasInstallLock(rootCfg) {
363-
// FIXME: in testing, the "app data" directory is not correctly initialized before loading settings
364-
if _, err := os.Stat(AppDataPath); err != nil {
365-
_ = os.MkdirAll(AppDataPath, os.ModePerm)
366-
}
367-
}
368371

369372
appTempPathInternal = sec.Key("APP_TEMP_PATH").String()
370373
if appTempPathInternal != "" {
@@ -375,9 +378,9 @@ func loadServerFrom(rootCfg ConfigProvider) {
375378

376379
EnableGzip = sec.Key("ENABLE_GZIP").MustBool()
377380
EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false)
378-
PprofDataPath = sec.Key("PPROF_DATA_PATH").MustString(filepath.Join(AppWorkPath, "data/tmp/pprof"))
381+
PprofDataPath = sec.Key("PPROF_DATA_PATH").MustString(filepath.Join(AppDataPath, "tmp/pprof"))
379382
if !filepath.IsAbs(PprofDataPath) {
380-
PprofDataPath = filepath.Join(AppWorkPath, PprofDataPath)
383+
PprofDataPath = filepath.Join(AppDataPath, PprofDataPath)
381384
}
382385
checkOverlappedPath("[server].PPROF_DATA_PATH", PprofDataPath)
383386

0 commit comments

Comments
 (0)