Use os.UserHomeDir(); closes #40

pull/42/head
Miguel Mota 5 years ago
parent f2027ca78c
commit 3211bd7f52
No known key found for this signature in database
GPG Key ID: 67EC1161588A00F9

@ -415,7 +415,7 @@ func Reset() error {
}
// default config path
configPath := fmt.Sprintf("%s%s", UserHomeDir(), "/.cointop")
configPath := fmt.Sprintf("%s%s", UserPreferredHomeDir(), "/.cointop")
if _, err := os.Stat(configPath); !os.IsNotExist(err) {
fmt.Printf("removing %s\n", configPath)
if err := os.RemoveAll(configPath); err != nil {

@ -28,28 +28,28 @@ func GetBytes(key interface{}) ([]byte, error) {
return buf.Bytes(), nil
}
// UserHomeDir returns home directory for the user
func UserHomeDir() string {
// UserPreferredHomeDir returns the preferred home directory for the user
func UserPreferredHomeDir() string {
var home string
if runtime.GOOS == "windows" {
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
if home == "" {
home = os.Getenv("USERPROFILE")
}
return home
home = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
} else if runtime.GOOS == "linux" {
home := os.Getenv("XDG_CONFIG_HOME")
if home != "" {
return home
}
home = os.Getenv("XDG_CONFIG_HOME")
}
if home == "" {
home, _ = os.UserHomeDir()
}
return os.Getenv("HOME")
return home
}
// NormalizePath normalizes and extends the path string
func NormalizePath(path string) string {
// expand tilde
if strings.HasPrefix(path, "~/") {
path = filepath.Join(UserHomeDir(), path[2:])
path = filepath.Join(UserPreferredHomeDir(), path[2:])
}
path = strings.Replace(path, "/", string(filepath.Separator), -1)

Loading…
Cancel
Save