mirror of
https://github.com/octoleo/restic.git
synced 2024-12-26 20:30:19 +00:00
29 lines
601 B
Go
29 lines
601 B
Go
// 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
|
|
}
|