Skip to content

Make AppDataPath absolute against the AppWorkPath if it is not #19815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,18 @@ func getWorkPath(appPath string) string {
workPath = appPath[:i]
}
}
workPath = strings.ReplaceAll(workPath, "\\", "/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filepath.Join can deal with backslashes on Windows. It doesn't need such hacks. After all, backslash is a valid path character on many file sytems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to be consistent with the rest of the filepath munging in this file.

if !filepath.IsAbs(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, "\\", "/")
}

Expand Down Expand Up @@ -769,6 +781,10 @@ 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) {
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))
}

EnableGzip = sec.Key("ENABLE_GZIP").MustBool()
EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false)
Expand Down