mirror of https://github.com/docker/docs.git
Merge pull request #88 from MSOpenTech/homedir
Fix #68. Homedir is now detected same as Docker.
This commit is contained in:
commit
ee98043c5a
|
@ -4,16 +4,18 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
homedir "github.com/mitchellh/go-homedir"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func PublicKeyPath() string {
|
func GetHomeDir() string {
|
||||||
homeDir, err := homedir.Dir()
|
if runtime.GOOS == "windows" {
|
||||||
if err != nil {
|
return os.Getenv("USERPROFILE")
|
||||||
homeDir = ""
|
|
||||||
}
|
}
|
||||||
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 {
|
func AddPublicKeyToAuthorizedHosts(d Driver, authorizedKeysPath string) error {
|
||||||
|
|
8
store.go
8
store.go
|
@ -7,7 +7,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
homedir "github.com/mitchellh/go-homedir"
|
"github.com/docker/machine/drivers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Store persists hosts on the filesystem
|
// Store persists hosts on the filesystem
|
||||||
|
@ -16,11 +16,7 @@ type Store struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStore() *Store {
|
func NewStore() *Store {
|
||||||
homeDir, err := homedir.Dir()
|
rootPath := path.Join(drivers.GetHomeDir(), ".docker/hosts")
|
||||||
if err != nil {
|
|
||||||
log.Errorf("error getting home directory : %s", err)
|
|
||||||
}
|
|
||||||
rootPath := path.Join(homeDir, ".docker/hosts")
|
|
||||||
return &Store{Path: rootPath}
|
return &Store{Path: rootPath}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,16 +5,12 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
none "github.com/docker/machine/drivers/none"
|
"github.com/docker/machine/drivers"
|
||||||
homedir "github.com/mitchellh/go-homedir"
|
"github.com/docker/machine/drivers/none"
|
||||||
)
|
)
|
||||||
|
|
||||||
func clearHosts() error {
|
func clearHosts() error {
|
||||||
homeDir, err := homedir.Dir()
|
return os.RemoveAll(path.Join(drivers.GetHomeDir(), ".docker/hosts"))
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return os.RemoveAll(path.Join(homeDir, ".docker/hosts"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStoreCreate(t *testing.T) {
|
func TestStoreCreate(t *testing.T) {
|
||||||
|
@ -31,11 +27,7 @@ func TestStoreCreate(t *testing.T) {
|
||||||
if host.Name != "test" {
|
if host.Name != "test" {
|
||||||
t.Fatal("Host name is incorrect")
|
t.Fatal("Host name is incorrect")
|
||||||
}
|
}
|
||||||
homeDir, err := homedir.Dir()
|
path := path.Join(drivers.GetHomeDir(), ".docker/hosts/test")
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
path := path.Join(homeDir, ".docker/hosts/test")
|
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
t.Fatalf("Host path doesn't exist: %s", path)
|
t.Fatalf("Host path doesn't exist: %s", path)
|
||||||
}
|
}
|
||||||
|
@ -52,11 +44,7 @@ func TestStoreRemove(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
homeDir, err := homedir.Dir()
|
path := path.Join(drivers.GetHomeDir(), ".docker/hosts/test")
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
path := path.Join(homeDir, ".docker/hosts/test")
|
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
t.Fatalf("Host path doesn't exist: %s", path)
|
t.Fatalf("Host path doesn't exist: %s", path)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue