diff --git a/drivers/utils.go b/drivers/utils.go index 6f0b714b51..aaa9d57be0 100644 --- a/drivers/utils.go +++ b/drivers/utils.go @@ -4,16 +4,18 @@ import ( "fmt" "os" "path/filepath" - - homedir "github.com/mitchellh/go-homedir" + "runtime" ) -func PublicKeyPath() string { - homeDir, err := homedir.Dir() - if err != nil { - homeDir = "" +func GetHomeDir() string { + if runtime.GOOS == "windows" { + return os.Getenv("USERPROFILE") } - return filepath.Join(homeDir, ".docker/public-key.json") + return os.Getenv("HOME") +} + +func PublicKeyPath() string { + return filepath.Join(GetHomeDir(), ".docker/public-key.json") } func AddPublicKeyToAuthorizedHosts(d Driver, authorizedKeysPath string) error { diff --git a/store.go b/store.go index 0b66925c26..6994cb899a 100644 --- a/store.go +++ b/store.go @@ -7,7 +7,7 @@ import ( "path" log "github.com/Sirupsen/logrus" - homedir "github.com/mitchellh/go-homedir" + "github.com/docker/machine/drivers" ) // Store persists hosts on the filesystem @@ -16,11 +16,7 @@ type Store struct { } func NewStore() *Store { - homeDir, err := homedir.Dir() - if err != nil { - log.Errorf("error getting home directory : %s", err) - } - rootPath := path.Join(homeDir, ".docker/hosts") + rootPath := path.Join(drivers.GetHomeDir(), ".docker/hosts") return &Store{Path: rootPath} } diff --git a/store_test.go b/store_test.go index 0139bda9d0..79af244219 100644 --- a/store_test.go +++ b/store_test.go @@ -5,16 +5,12 @@ import ( "path" "testing" - none "github.com/docker/machine/drivers/none" - homedir "github.com/mitchellh/go-homedir" + "github.com/docker/machine/drivers" + "github.com/docker/machine/drivers/none" ) func clearHosts() error { - homeDir, err := homedir.Dir() - if err != nil { - return err - } - return os.RemoveAll(path.Join(homeDir, ".docker/hosts")) + return os.RemoveAll(path.Join(drivers.GetHomeDir(), ".docker/hosts")) } func TestStoreCreate(t *testing.T) { @@ -31,11 +27,7 @@ func TestStoreCreate(t *testing.T) { if host.Name != "test" { t.Fatal("Host name is incorrect") } - homeDir, err := homedir.Dir() - if err != nil { - t.Fatal(err) - } - path := path.Join(homeDir, ".docker/hosts/test") + path := path.Join(drivers.GetHomeDir(), ".docker/hosts/test") if _, err := os.Stat(path); os.IsNotExist(err) { t.Fatalf("Host path doesn't exist: %s", path) } @@ -52,11 +44,7 @@ func TestStoreRemove(t *testing.T) { if err != nil { t.Fatal(err) } - homeDir, err := homedir.Dir() - if err != nil { - t.Fatal(err) - } - path := path.Join(homeDir, ".docker/hosts/test") + path := path.Join(drivers.GetHomeDir(), ".docker/hosts/test") if _, err := os.Stat(path); os.IsNotExist(err) { t.Fatalf("Host path doesn't exist: %s", path) }