fix: decouple project root resolution from custom BH_CONFIG_PATH env
This commit is contained in:
@@ -34,13 +34,7 @@ func init() {
|
|||||||
|
|
||||||
// ResolveAppRootDir 获取应用程序的绝对根目录路径。
|
// ResolveAppRootDir 获取应用程序的绝对根目录路径。
|
||||||
func ResolveAppRootDir() string {
|
func ResolveAppRootDir() string {
|
||||||
// 1. 检查 BH_CONFIG_PATH 环境变量
|
// 1. 检查当前可执行文件路径
|
||||||
if configPath := os.Getenv("BH_CONFIG_PATH"); configPath != "" {
|
|
||||||
if absConfigPath, err := filepath.Abs(configPath); err == nil {
|
|
||||||
return filepath.Dir(filepath.Dir(absConfigPath))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 2. 检查当前可执行文件路径
|
|
||||||
if exe, err := os.Executable(); err == nil {
|
if exe, err := os.Executable(); err == nil {
|
||||||
dir := filepath.Dir(exe)
|
dir := filepath.Dir(exe)
|
||||||
for {
|
for {
|
||||||
@@ -57,7 +51,7 @@ func ResolveAppRootDir() string {
|
|||||||
dir = parent
|
dir = parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 3. 回退到当前工作目录
|
// 2. 回退到当前工作目录
|
||||||
if cwd, err := os.Getwd(); err == nil {
|
if cwd, err := os.Getwd(); err == nil {
|
||||||
return cwd
|
return cwd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,22 +93,7 @@ func ResolveAbsScriptsDir() string {
|
|||||||
return filepath.Clean(scriptsDir)
|
return filepath.Clean(scriptsDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
if configPath := os.Getenv("BH_CONFIG_PATH"); configPath != "" {
|
return constant.ScriptsWorkDir
|
||||||
if !filepath.IsAbs(configPath) {
|
|
||||||
if absConfigPath, err := filepath.Abs(configPath); err == nil {
|
|
||||||
configPath = absConfigPath
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
projectRoot := filepath.Dir(filepath.Dir(configPath))
|
|
||||||
return filepath.Clean(filepath.Join(projectRoot, constant.ScriptsWorkDir))
|
|
||||||
}
|
|
||||||
|
|
||||||
if absScriptsDir, err := filepath.Abs(constant.ScriptsWorkDir); err == nil {
|
|
||||||
return absScriptsDir
|
|
||||||
}
|
|
||||||
|
|
||||||
return filepath.Clean(constant.ScriptsWorkDir)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendEnvIfSet(envs *[]string, key, value string) {
|
func appendEnvIfSet(envs *[]string, key, value string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user