Skip to content

Commit

Permalink
fix: use executable file path instead of pwd
Browse files Browse the repository at this point in the history
  • Loading branch information
creamlike1024 committed May 2, 2024
1 parent 3c4f1c5 commit 26aba9d
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,24 @@ type Config struct {
var ConfigInstance Config

func LoadConfig() error {
exePath, err := os.Executable()
if err != nil {
return err
}
exePath, err = filepath.EvalSymlinks(exePath)
if err != nil {
return err
}
exeDir := filepath.Dir(exePath)

switch platform := runtime.GOOS; platform {
case "windows":
ConfigInstance.EXEName = "lpac.exe"
pwd, err := os.Getwd()
if err != nil {
return err
}
ConfigInstance.LpacDir = pwd
ConfigInstance.LogDir = filepath.Join(pwd, "log")
case "darwin":
ConfigInstance.EXEName = "lpac"
exePath, err := os.Executable()
if err != nil {
return err
}
ConfigInstance.LpacDir = filepath.Dir(exePath)
ConfigInstance.LogDir = filepath.Join("/tmp", "EasyLPAC-log")
ConfigInstance.LpacDir = exeDir
ConfigInstance.LogDir = filepath.Join(exeDir, "log")
default:
ConfigInstance.EXEName = "lpac"
exePath, err := os.Executable()
if err != nil {
return err
}
ConfigInstance.LpacDir = filepath.Dir(exePath)
ConfigInstance.LpacDir = exeDir
ConfigInstance.LogDir = filepath.Join("/tmp", "EasyLPAC-log")
}

Expand Down

0 comments on commit 26aba9d

Please sign in to comment.