From 5b47751d841f0658f7c4861528ba96a7e0ee7563 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Thu, 26 May 2022 21:35:30 +0100 Subject: [PATCH 1/3] 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 --- modules/setting/setting.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 5e317b39ea289..2515648d8be05 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -478,6 +478,10 @@ func getWorkPath(appPath string) string { workPath = appPath[:i] } } + workPath = strings.ReplaceAll(workPath, "\\", "/") + if !filepath.IsAbs(workPath) { + workPath = filepath.Join(appPath, workPath) + } return strings.ReplaceAll(workPath, "\\", "/") } @@ -769,6 +773,9 @@ func loadFromConf(allowEmpty bool, extraConfig string) { StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(StaticRootPath) StaticCacheTime = sec.Key("STATIC_CACHE_TIME").MustDuration(6 * time.Hour) AppDataPath = sec.Key("APP_DATA_PATH").MustString(path.Join(AppWorkPath, "data")) + if !filepath.IsAbs(AppDataPath) { + AppDataPath = filepath.ToSlash(filepath.Join(AppWorkPath, AppDataPath)) + } EnableGzip = sec.Key("ENABLE_GZIP").MustBool() EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false) From c9fcfd1409d0a2d649496f61dd6150f1bd4863b9 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Wed, 1 Jun 2022 18:29:14 +0100 Subject: [PATCH 2/3] Add logging Signed-off-by: Andrew Thornton --- modules/setting/setting.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 2515648d8be05..90fb434fc491a 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -480,6 +480,7 @@ func getWorkPath(appPath string) string { } workPath = strings.ReplaceAll(workPath, "\\", "/") if !filepath.IsAbs(workPath) { + log.Info("Provided work path %s is not absolute - will be absoluted against %s", workPath, appPath) workPath = filepath.Join(appPath, workPath) } return strings.ReplaceAll(workPath, "\\", "/") @@ -774,6 +775,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) { StaticCacheTime = sec.Key("STATIC_CACHE_TIME").MustDuration(6 * time.Hour) AppDataPath = sec.Key("APP_DATA_PATH").MustString(path.Join(AppWorkPath, "data")) if !filepath.IsAbs(AppDataPath) { + log.Info("The provided APP_DATA_PATH: %s is not absolute - it will be made absolute against the work path: %s", AppDataPath, AppWorkPath) AppDataPath = filepath.ToSlash(filepath.Join(AppWorkPath, AppDataPath)) } From b476d89d18118fd01155654b3f1b927dfa0f9b7d Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Wed, 1 Jun 2022 18:46:50 +0100 Subject: [PATCH 3/3] absolute workpath against pwd instead of app path first Signed-off-by: Andrew Thornton --- modules/setting/setting.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 90fb434fc491a..88f306b3fa7e3 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -480,8 +480,15 @@ func getWorkPath(appPath string) string { } workPath = strings.ReplaceAll(workPath, "\\", "/") if !filepath.IsAbs(workPath) { - log.Info("Provided work path %s is not absolute - will be absoluted against %s", workPath, appPath) - workPath = filepath.Join(appPath, workPath) + log.Info("Provided work path %s is not absolute - will be made absolute against the current working directory", workPath) + + absPath, err := filepath.Abs(workPath) + if err != nil { + log.Error("Unable to absolute %s against the current working directory %v. Will absolute against the AppPath %s", workPath, err, appPath) + workPath = filepath.Join(appPath, workPath) + } else { + workPath = absPath + } } return strings.ReplaceAll(workPath, "\\", "/") }