aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-06-23 17:48:14 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-06-23 18:03:58 +0200
commita64aa619d31130d08e228b467516c8cb7e814973 (patch)
tree0adb3d12330a73c425c5fbc905e538b647b80ffa
parentf53cc64ea17876c7ad8f088fc069448b2414b808 (diff)
Support $HOME on Windows host.
-rw-r--r--lib/common/filepath.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/common/filepath.go b/lib/common/filepath.go
index 4c8c0da..d9cb3d5 100644
--- a/lib/common/filepath.go
+++ b/lib/common/filepath.go
@@ -7,6 +7,7 @@ import (
"path"
"path/filepath"
"regexp"
+ "runtime"
)
// Exists returns whether the given file or directory exists or not
@@ -42,7 +43,14 @@ func ResolveEnvVar(s string) (string, error) {
for _, v := range vars {
val := os.Getenv(v[1])
if val == "" {
- return res, fmt.Errorf("ERROR: %s env variable not defined", v[1])
+ // Specific case to resolved $HOME or ${HOME} on Windows host
+ if runtime.GOOS == "windows" && v[1] == "HOME" {
+ if usr, err := user.Current(); err == nil {
+ val = usr.HomeDir
+ }
+ } else {
+ return res, fmt.Errorf("ERROR: %s env variable not defined", v[1])
+ }
}
rer := regexp.MustCompile("\\${" + v[1] + "}")