summaryrefslogtreecommitdiffstats
path: root/golib/filepath.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-09-22 17:15:53 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-09-22 17:15:53 +0200
commitfbfecfe0ac37ee34c940566c3b7741426f67489a (patch)
tree479288b5d9fc46436c9ed68955e62870cc8b5ad3 /golib/filepath.go
parentf668c6cc855dae530ac71d4ef82e78ecc20a8f84 (diff)
Added GetExePathv0.1.2
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'golib/filepath.go')
-rw-r--r--golib/filepath.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/golib/filepath.go b/golib/filepath.go
index c91f63d..1817f58 100644
--- a/golib/filepath.go
+++ b/golib/filepath.go
@@ -55,18 +55,7 @@ func ResolveEnvVar(s string) (string, error) {
val := ""
if v[1] == "EXEPATH" {
// Specific case to resolve $EXEPATH or ${EXEPATH} used as current executable path
- exePath := os.Args[0]
- ee, _ := os.Executable()
- exeAbsPath, err := filepath.Abs(ee)
- if err == nil {
- exePath, err = filepath.EvalSymlinks(exeAbsPath)
- if err == nil {
- exePath = filepath.Dir(ee)
- } else {
- exePath = filepath.Dir(exeAbsPath)
- }
- }
- val = exePath
+ val = GetExePath()
} else {
// Get env var value
@@ -122,3 +111,19 @@ func GetUserHome() string {
return ""
}
+
+// GetExePath returns the full path of the current executable
+func GetExePath() string {
+ exePath := os.Args[0] // set fallback value
+ ee, _ := os.Executable()
+ exeAbsPath, err := filepath.Abs(ee)
+ if err == nil {
+ exePath, err = filepath.EvalSymlinks(exeAbsPath)
+ if err == nil {
+ exePath = filepath.Dir(ee)
+ } else {
+ exePath = filepath.Dir(exeAbsPath)
+ }
+ }
+ return exePath
+}