fix: remove user.current()

relates to #55
This commit is contained in:
Jan De Dobbeleer 2020-10-12 16:01:08 +02:00 committed by Jan De Dobbeleer
parent 56f4bcfd86
commit 56468baf4c
3 changed files with 14 additions and 11 deletions

View file

@ -5,7 +5,6 @@ import (
"log"
"os"
"os/exec"
"os/user"
"path/filepath"
"runtime"
"strings"
@ -64,16 +63,6 @@ func (env *environment) getcwd() string {
return env.cwd
}
func (env *environment) homeDir() string {
usr, err := user.Current()
if err != nil {
return ""
}
homeDir := usr.HomeDir
// on Windows, and being case sentisitive and not consistent and all, this gives silly issues
return strings.Replace(homeDir, "c:", "C:", 1)
}
func (env *environment) hasFiles(pattern string) bool {
cwd := env.getcwd()
pattern = cwd + env.getPathSeperator() + pattern

View file

@ -9,3 +9,7 @@ import (
func (env *environment) isRunningAsRoot() bool {
return os.Geteuid() == 0
}
func (env *environment) homeDir() string {
return os.Getenv("HOME")
}

View file

@ -1,6 +1,8 @@
package main
import (
"os"
"golang.org/x/sys/windows"
)
@ -35,3 +37,11 @@ func (env *environment) isRunningAsRoot() bool {
return member
}
func (env *environment) homeDir() string {
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
if home == "" {
home = os.Getenv("USERPROFILE")
}
return home
}