summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/minio/go-homedir/dir_windows.go
blob: 85e5218c7fceb47f01c036852e62d1aa8067af7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2016 (C) Mitchell Hashimoto
// Distributed under the MIT License.

package homedir

import (
	"errors"
	"os"
)

// dir returns the homedir of current user for MS Windows OS.
func dir() (string, error) {
	// First prefer the HOME environmental variable
	if home := os.Getenv("HOME"); home != "" {
		return home, nil
	}
	drive := os.Getenv("HOMEDRIVE")
	path := os.Getenv("HOMEPATH")
	home := drive + path
	if drive == "" || path == "" {
		home = os.Getenv("USERPROFILE")
	}
	if home == "" {
		return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank")
	}

	return home, nil
}