diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 4e2a32fa9e..7ed76c0ada 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -115,10 +115,6 @@ "ImportPath": "github.com/google/go-querystring/query", "Rev": "30f7a39f4a218feb5325f3aebc60c32a572a8274" }, - { - "ImportPath": "github.com/mitchellh/go-homedir", - "Rev": "7d2d8c8a4e078ce3c58736ab521a40b37a504c52" - }, { "ImportPath": "github.com/tent/http-link-go", "Rev": "ac974c61c2f990f4115b119354b5e0b47550e888" diff --git a/Godeps/_workspace/src/github.com/mitchellh/go-homedir/LICENSE b/Godeps/_workspace/src/github.com/mitchellh/go-homedir/LICENSE deleted file mode 100644 index f9c841a51e..0000000000 --- a/Godeps/_workspace/src/github.com/mitchellh/go-homedir/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 Mitchell Hashimoto - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/Godeps/_workspace/src/github.com/mitchellh/go-homedir/README.md b/Godeps/_workspace/src/github.com/mitchellh/go-homedir/README.md deleted file mode 100644 index d70706d5b3..0000000000 --- a/Godeps/_workspace/src/github.com/mitchellh/go-homedir/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# go-homedir - -This is a Go library for detecting the user's home directory without -the use of cgo, so the library can be used in cross-compilation environments. - -Usage is incredibly simple, just call `homedir.Dir()` to get the home directory -for a user, and `homedir.Expand()` to expand the `~` in a path to the home -directory. - -**Why not just use `os/user`?** The built-in `os/user` package requires -cgo on Darwin systems. This means that any Go code that uses that package -cannot cross compile. But 99% of the time the use for `os/user` is just to -retrieve the home directory, which we can do for the current user without -cgo. This library does that, enabling cross-compilation. diff --git a/Godeps/_workspace/src/github.com/mitchellh/go-homedir/homedir.go b/Godeps/_workspace/src/github.com/mitchellh/go-homedir/homedir.go deleted file mode 100644 index b6d35027b7..0000000000 --- a/Godeps/_workspace/src/github.com/mitchellh/go-homedir/homedir.go +++ /dev/null @@ -1,83 +0,0 @@ -package homedir - -import ( - "bytes" - "errors" - "os" - "os/exec" - "runtime" - "strings" -) - -// Dir returns the home directory for the executing user. -// -// This uses an OS-specific method for discovering the home directory. -// An error is returned if a home directory cannot be detected. -func Dir() (string, error) { - if runtime.GOOS == "windows" { - return dirWindows() - } - - // Unix-like system, so just assume Unix - return dirUnix() -} - -// Expand expands the path to include the home directory if the path -// is prefixed with `~`. If it isn't prefixed with `~`, the path is -// returned as-is. -func Expand(path string) (string, error) { - if len(path) == 0 { - return path, nil - } - - if path[0] != '~' { - return path, nil - } - - if len(path) > 1 && path[1] != '/' && path[1] != '\\' { - return "", errors.New("cannot expand user-specific home dir") - } - - dir, err := Dir() - if err != nil { - return "", err - } - - return dir + path[1:], nil -} - -func dirUnix() (string, error) { - // First prefer the HOME environmental variable - if home := os.Getenv("HOME"); home != "" { - return home, nil - } - - // If that fails, try the shell - var stdout bytes.Buffer - cmd := exec.Command("sh", "-c", "eval echo ~$USER") - cmd.Stdout = &stdout - if err := cmd.Run(); err != nil { - return "", err - } - - result := strings.TrimSpace(stdout.String()) - if result == "" { - return "", errors.New("blank output when reading home directory") - } - - return result, nil -} - -func dirWindows() (string, error) { - 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 -} diff --git a/Godeps/_workspace/src/github.com/mitchellh/go-homedir/homedir_test.go b/Godeps/_workspace/src/github.com/mitchellh/go-homedir/homedir_test.go deleted file mode 100644 index 89e74c3784..0000000000 --- a/Godeps/_workspace/src/github.com/mitchellh/go-homedir/homedir_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package homedir - -import ( - "fmt" - "os/user" - "testing" -) - -func TestDir(t *testing.T) { - u, err := user.Current() - if err != nil { - t.Fatalf("err: %s", err) - } - - dir, err := Dir() - if err != nil { - t.Fatalf("err: %s", err) - } - - if u.HomeDir != dir { - t.Fatalf("%#v != %#v", u.HomeDir, dir) - } -} - -func TestExpand(t *testing.T) { - u, err := user.Current() - if err != nil { - t.Fatalf("err: %s", err) - } - - cases := []struct { - Input string - Output string - Err bool - }{ - { - "/foo", - "/foo", - false, - }, - - { - "~/foo", - fmt.Sprintf("%s/foo", u.HomeDir), - false, - }, - - { - "", - "", - false, - }, - - { - "~", - u.HomeDir, - false, - }, - - { - "~foo/foo", - "", - true, - }, - } - - for _, tc := range cases { - actual, err := Expand(tc.Input) - if (err != nil) != tc.Err { - t.Fatalf("Input: %#v\n\nErr: %s", tc.Input, err) - } - - if actual != tc.Output { - t.Fatalf("Input: %#v\n\nOutput: %#v", tc.Input, actual) - } - } -} diff --git a/drivers/azure/azure.go b/drivers/azure/azure.go index 1e1175098d..64ad957b55 100644 --- a/drivers/azure/azure.go +++ b/drivers/azure/azure.go @@ -5,7 +5,7 @@ import ( "net" "os" "os/exec" - "path" + "path/filepath" "strconv" "strings" "time" @@ -562,7 +562,7 @@ func (driver *Driver) generateCertForAzure() error { } func (driver *Driver) sshKeyPath() string { - return path.Join(driver.storePath, "id_rsa") + return filepath.Join(driver.storePath, "id_rsa") } func (driver *Driver) publicSSHKeyPath() string { @@ -570,5 +570,5 @@ func (driver *Driver) publicSSHKeyPath() string { } func (driver *Driver) azureCertPath() string { - return path.Join(driver.storePath, "azure_cert.pem") + return filepath.Join(driver.storePath, "azure_cert.pem") } diff --git a/drivers/digitalocean/digitalocean.go b/drivers/digitalocean/digitalocean.go index 2ef263270f..d8aee7eb03 100644 --- a/drivers/digitalocean/digitalocean.go +++ b/drivers/digitalocean/digitalocean.go @@ -5,7 +5,7 @@ import ( "io/ioutil" "os" "os/exec" - "path" + "path/filepath" "time" "code.google.com/p/goauth2/oauth" @@ -323,7 +323,7 @@ func (d *Driver) getClient() *godo.Client { } func (d *Driver) sshKeyPath() string { - return path.Join(d.storePath, "id_rsa") + return filepath.Join(d.storePath, "id_rsa") } func (d *Driver) publicSSHKeyPath() string { diff --git a/drivers/utils.go b/drivers/utils.go index 6f0b714b51..a15b75c6ef 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/drivers/virtualbox/virtualbox.go b/drivers/virtualbox/virtualbox.go index d913638d8c..4a4ec1a497 100644 --- a/drivers/virtualbox/virtualbox.go +++ b/drivers/virtualbox/virtualbox.go @@ -11,7 +11,7 @@ import ( "net/http" "os" "os/exec" - "path" + "path/filepath" "regexp" "runtime" "strconv" @@ -209,7 +209,7 @@ func (d *Driver) Create() error { "--port", "0", "--device", "0", "--type", "dvddrive", - "--medium", path.Join(d.storePath, "boot2docker.iso")); err != nil { + "--medium", filepath.Join(d.storePath, "boot2docker.iso")); err != nil { return err } @@ -434,7 +434,7 @@ func (d *Driver) GetSSHCommand(args ...string) (*exec.Cmd, error) { } func (d *Driver) sshKeyPath() string { - return path.Join(d.storePath, "id_rsa") + return filepath.Join(d.storePath, "id_rsa") } func (d *Driver) publicSSHKeyPath() string { @@ -442,7 +442,7 @@ func (d *Driver) publicSSHKeyPath() string { } func (d *Driver) diskPath() string { - return path.Join(d.storePath, "disk.vmdk") + return filepath.Join(d.storePath, "disk.vmdk") } // Get the latest boot2docker release tag name (e.g. "v0.6.0"). @@ -490,7 +490,7 @@ func downloadISO(dir, file, url string) error { if err := f.Close(); err != nil { return err } - if err := os.Rename(f.Name(), path.Join(dir, file)); err != nil { + if err := os.Rename(f.Name(), filepath.Join(dir, file)); err != nil { return err } return nil diff --git a/host.go b/host.go index aa3476034b..8a8270dfaf 100644 --- a/host.go +++ b/host.go @@ -5,7 +5,7 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" "regexp" log "github.com/Sirupsen/logrus" @@ -105,7 +105,7 @@ func (h *Host) GetURL() (string, error) { } func (h *Host) LoadConfig() error { - data, err := ioutil.ReadFile(path.Join(h.storePath, "config.json")) + data, err := ioutil.ReadFile(filepath.Join(h.storePath, "config.json")) if err != nil { return err } @@ -135,7 +135,7 @@ func (h *Host) SaveConfig() error { if err != nil { return err } - if err := ioutil.WriteFile(path.Join(h.storePath, "config.json"), data, 0600); err != nil { + if err := ioutil.WriteFile(filepath.Join(h.storePath, "config.json"), data, 0600); err != nil { return err } return nil diff --git a/store.go b/store.go index 0b66925c26..93d13fc703 100644 --- a/store.go +++ b/store.go @@ -4,10 +4,10 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" 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 := filepath.Join(drivers.GetHomeDir(), ".docker", "hosts") return &Store{Path: rootPath} } @@ -33,7 +29,7 @@ func (s *Store) Create(name string, driverName string, createFlags interface{}) return nil, fmt.Errorf("Host %q already exists", name) } - hostPath := path.Join(s.Path, name) + hostPath := filepath.Join(s.Path, name) host, err := NewHost(name, driverName, hostPath) if err != nil { @@ -99,7 +95,7 @@ func (s *Store) List() ([]Host, error) { } func (s *Store) Exists(name string) (bool, error) { - _, err := os.Stat(path.Join(s.Path, name)) + _, err := os.Stat(filepath.Join(s.Path, name)) if os.IsNotExist(err) { return false, nil } else if err == nil { @@ -109,7 +105,7 @@ func (s *Store) Exists(name string) (bool, error) { } func (s *Store) Load(name string) (*Host, error) { - hostPath := path.Join(s.Path, name) + hostPath := filepath.Join(s.Path, name) return LoadHost(name, hostPath) } @@ -135,7 +131,7 @@ func (s *Store) IsActive(host *Host) (bool, error) { } func (s *Store) SetActive(host *Host) error { - if err := os.MkdirAll(path.Dir(s.activePath()), 0700); err != nil { + if err := os.MkdirAll(filepath.Dir(s.activePath()), 0700); err != nil { return err } return ioutil.WriteFile(s.activePath(), []byte(host.Name), 0600) @@ -148,5 +144,5 @@ func (s *Store) RemoveActive() error { // activePath returns the path to the file that stores the name of the // active host func (s *Store) activePath() string { - return path.Join(s.Path, ".active") + return filepath.Join(s.Path, ".active") } diff --git a/store_test.go b/store_test.go index 0139bda9d0..2679ff158d 100644 --- a/store_test.go +++ b/store_test.go @@ -2,19 +2,15 @@ package main import ( "os" - "path" + "path/filepath" "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(filepath.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 := filepath.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 := filepath.Join(drivers.GetHomeDir(), ".docker", "hosts", "test") if _, err := os.Stat(path); os.IsNotExist(err) { t.Fatalf("Host path doesn't exist: %s", path) }