Cleaned up home directory handling and started cache package
diff --git a/action/ensure.go b/action/ensure.go
index 041cfce..2f5f5af 100644
--- a/action/ensure.go
+++ b/action/ensure.go
@@ -59,11 +59,6 @@
return conf
}
-// EnsureCacheDir ensures the existence of the cache directory
-func EnsureCacheDir() {
- msg.Warn("ensure.go: ensureCacheDir is not implemented.")
-}
-
// EnsureGoVendor ensures that the Go version is correct.
func EnsureGoVendor() {
// 6l was removed in 1.5, when vendoring was introduced.
@@ -148,7 +143,6 @@
return ""
}
-
// goExecutable checks for a set environment variable of GLIDE_GO_EXECUTABLE
// for the go executable name. The Google App Engine SDK ships with a python
// wrapper called goapp
diff --git a/action/init.go b/action/init.go
index b0c29da..2094902 100644
--- a/action/init.go
+++ b/action/init.go
@@ -7,5 +7,5 @@
// Init initializes the action subsystem for handling one or more subesequent actions.
func Init(yaml, home string) {
gpath.GlideFile = yaml
- gpath.HomeDir = home
+ gpath.SetHome(home)
}
diff --git a/cache/cache.go b/cache/cache.go
new file mode 100644
index 0000000..5f4732f
--- /dev/null
+++ b/cache/cache.go
@@ -0,0 +1,13 @@
+// Package cache provides an interface for interfacing with the Glide local cache
+package cache
+
+import (
+ "path/filepath"
+
+ gpath "github.com/Masterminds/glide/path"
+)
+
+// Location returns the location of the cache.
+func Location() string {
+ return filepath.Join(gpath.Home(), "cache")
+}
diff --git a/glide.go b/glide.go
index e205796..2f75f07 100644
--- a/glide.go
+++ b/glide.go
@@ -49,7 +49,6 @@
"fmt"
"os"
- "os/user"
)
var version = "0.11.0-dev"
@@ -97,7 +96,7 @@
},
cli.StringFlag{
Name: "home",
- Value: defaultGlideDir(),
+ Value: gpath.Home(),
Usage: "The location of Glide files",
EnvVar: "GLIDE_HOME",
},
@@ -444,7 +443,7 @@
installer.UseGopath = c.Bool("use-gopath")
installer.UseCacheGopath = c.Bool("cache-gopath")
installer.UpdateVendored = c.Bool("update-vendored")
- installer.Home = gpath.Home()
+ installer.Home = c.GlobalString("home")
installer.DeleteUnused = c.Bool("deleteOptIn")
action.Install(installer, c.Bool("strip-vcs"), c.Bool("strip-vendor"))
@@ -557,7 +556,7 @@
installer.UseCacheGopath = c.Bool("cache-gopath")
installer.UpdateVendored = c.Bool("update-vendored")
installer.ResolveAllFiles = c.Bool("all-dependencies")
- installer.Home = gpath.Home()
+ installer.Home = c.GlobalString("home")
installer.DeleteUnused = c.Bool("deleteOptIn")
action.Update(installer, c.Bool("no-recursive"), c.Bool("strip-vcs"), c.Bool("strip-vendor"))
@@ -649,14 +648,6 @@
}
}
-func defaultGlideDir() string {
- c, err := user.Current()
- if err != nil {
- return ""
- }
- return filepath.Join(c.HomeDir, ".glide")
-}
-
// startup sets up the base environment.
//
// It does not assume the presence of a Glide.yaml file or vendor/ directory,
diff --git a/path/path.go b/path/path.go
index 9e7162f..0b19442 100644
--- a/path/path.go
+++ b/path/path.go
@@ -8,6 +8,7 @@
"fmt"
"io"
"os"
+ "os/user"
"path/filepath"
"strings"
)
@@ -20,10 +21,8 @@
// As of Go 1.5, this is always vendor.
var VendorDir = "vendor"
-// HomeDir is the home directory for Glide.
-//
-// HomeDir is where cache files and other configuration data are stored.
-var HomeDir = "$HOME/.glide"
+// Cache the location of the homedirectory.
+var homeDir = ""
// GlideFile is the name of the Glide file.
//
@@ -38,12 +37,29 @@
//
// This normalizes to an absolute path, and passes through os.ExpandEnv.
func Home() string {
- h := os.ExpandEnv(HomeDir)
- var err error
- if h, err = filepath.Abs(HomeDir); err != nil {
- return HomeDir
+ if homeDir != "" {
+ return homeDir
}
- return h
+
+ // Initialize the default user.
+ u, err := user.Current()
+ if err == nil && u.HomeDir != "" {
+ homeDir = filepath.Join(u.HomeDir, ".glide")
+ } else {
+ cwd, err := os.Getwd()
+ if err == nil {
+ homeDir = filepath.Join(cwd, ".glide")
+ } else {
+ homeDir = ".glide"
+ }
+ }
+
+ return homeDir
+}
+
+// SetHome sets the home directory for Glide.
+func SetHome(h string) {
+ homeDir = h
}
// Vendor calculates the path to the vendor directory.