Skip to content

Commit c48706e

Browse files
zeripathlunny
andauthored
Make AppDataPath absolute against the AppWorkPath if it is not (#19815)
* Make AppDataPath absolute against the AppWorkPath if it is not There are multiple repeated issues whereby a non-absolute provided APP_DATA_PATH causes strange issues. This PR simply absolutes the APP_DATA_PATH against the AppWorkPath if its not so. It also ensures that AppWorkPath is also always absolute. Ref #19367 Signed-off-by: Andrew Thornton <art27@cantab.net> * Add logging Signed-off-by: Andrew Thornton <art27@cantab.net> * absolute workpath against pwd instead of app path first Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
1 parent 2609511 commit c48706e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

modules/setting/setting.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,18 @@ func getWorkPath(appPath string) string {
478478
workPath = appPath[:i]
479479
}
480480
}
481+
workPath = strings.ReplaceAll(workPath, "\\", "/")
482+
if !filepath.IsAbs(workPath) {
483+
log.Info("Provided work path %s is not absolute - will be made absolute against the current working directory", workPath)
484+
485+
absPath, err := filepath.Abs(workPath)
486+
if err != nil {
487+
log.Error("Unable to absolute %s against the current working directory %v. Will absolute against the AppPath %s", workPath, err, appPath)
488+
workPath = filepath.Join(appPath, workPath)
489+
} else {
490+
workPath = absPath
491+
}
492+
}
481493
return strings.ReplaceAll(workPath, "\\", "/")
482494
}
483495

@@ -769,6 +781,10 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
769781
StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(StaticRootPath)
770782
StaticCacheTime = sec.Key("STATIC_CACHE_TIME").MustDuration(6 * time.Hour)
771783
AppDataPath = sec.Key("APP_DATA_PATH").MustString(path.Join(AppWorkPath, "data"))
784+
if !filepath.IsAbs(AppDataPath) {
785+
log.Info("The provided APP_DATA_PATH: %s is not absolute - it will be made absolute against the work path: %s", AppDataPath, AppWorkPath)
786+
AppDataPath = filepath.ToSlash(filepath.Join(AppWorkPath, AppDataPath))
787+
}
772788

773789
EnableGzip = sec.Key("ENABLE_GZIP").MustBool()
774790
EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false)

0 commit comments

Comments
 (0)