summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mitchellh/go-homedir
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-06-21 13:10:40 -0700
committerHarrison Healey <harrisonmhealey@gmail.com>2018-06-21 16:10:40 -0400
commit8526739066ccb00ccd24b74650a7d7b284442985 (patch)
tree282512ae2ad95c98a9ca82de304a410b6b56685c /vendor/github.com/mitchellh/go-homedir
parenta59ccaa8b3844895dde3980e6224fef46ff4a1c8 (diff)
downloadchat-8526739066ccb00ccd24b74650a7d7b284442985.tar.gz
chat-8526739066ccb00ccd24b74650a7d7b284442985.tar.bz2
chat-8526739066ccb00ccd24b74650a7d7b284442985.zip
MM-10934 Update server dependencies. (#8981)
* Changing throttled import path. * Upgrading dependencies.
Diffstat (limited to 'vendor/github.com/mitchellh/go-homedir')
-rw-r--r--vendor/github.com/mitchellh/go-homedir/homedir.go46
1 files changed, 32 insertions, 14 deletions
diff --git a/vendor/github.com/mitchellh/go-homedir/homedir.go b/vendor/github.com/mitchellh/go-homedir/homedir.go
index 47e1f9ef8..acbb605d5 100644
--- a/vendor/github.com/mitchellh/go-homedir/homedir.go
+++ b/vendor/github.com/mitchellh/go-homedir/homedir.go
@@ -77,33 +77,51 @@ func Expand(path string) (string, error) {
}
func dirUnix() (string, error) {
+ homeEnv := "HOME"
+ if runtime.GOOS == "plan9" {
+ // On plan9, env vars are lowercase.
+ homeEnv = "home"
+ }
+
// First prefer the HOME environmental variable
- if home := os.Getenv("HOME"); home != "" {
+ if home := os.Getenv(homeEnv); home != "" {
return home, nil
}
- // If that fails, try getent
var stdout bytes.Buffer
- cmd := exec.Command("getent", "passwd", strconv.Itoa(os.Getuid()))
- cmd.Stdout = &stdout
- if err := cmd.Run(); err != nil {
- // If the error is ErrNotFound, we ignore it. Otherwise, return it.
- if err != exec.ErrNotFound {
- return "", err
+
+ // If that fails, try OS specific commands
+ if runtime.GOOS == "darwin" {
+ cmd := exec.Command("sh", "-c", `dscl -q . -read /Users/"$(whoami)" NFSHomeDirectory | sed 's/^[^ ]*: //'`)
+ cmd.Stdout = &stdout
+ if err := cmd.Run(); err == nil {
+ result := strings.TrimSpace(stdout.String())
+ if result != "" {
+ return result, nil
+ }
}
} else {
- if passwd := strings.TrimSpace(stdout.String()); passwd != "" {
- // username:password:uid:gid:gecos:home:shell
- passwdParts := strings.SplitN(passwd, ":", 7)
- if len(passwdParts) > 5 {
- return passwdParts[5], nil
+ cmd := exec.Command("getent", "passwd", strconv.Itoa(os.Getuid()))
+ cmd.Stdout = &stdout
+ if err := cmd.Run(); err != nil {
+ // If the error is ErrNotFound, we ignore it. Otherwise, return it.
+ if err != exec.ErrNotFound {
+ return "", err
+ }
+ } else {
+ if passwd := strings.TrimSpace(stdout.String()); passwd != "" {
+ // username:password:uid:gid:gecos:home:shell
+ passwdParts := strings.SplitN(passwd, ":", 7)
+ if len(passwdParts) > 5 {
+ return passwdParts[5], nil
+ }
}
}
}
// If all else fails, try the shell
stdout.Reset()
- cmd = exec.Command("sh", "-c", "cd && pwd")
+ cmd := exec.Command("sh", "-c", "cd && pwd")
cmd.Stdout = &stdout
if err := cmd.Run(); err != nil {
return "", err