Merge pull request #88 from MSOpenTech/homedir

Fix #68. Homedir is now detected same as Docker.
This commit is contained in:
Ben Firshman 2014-12-12 00:22:53 +00:00
commit ee98043c5a
3 changed files with 16 additions and 30 deletions

View File

@ -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 {

View File

@ -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}
}

View File

@ -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)
}