Fixes #135 where Glide would hard fail for no home directory Also fixed #137 where some messages did not end in \n
diff --git a/.gitignore b/.gitignore index 19b111a..0b9c8d1 100644 --- a/.gitignore +++ b/.gitignore
@@ -4,4 +4,5 @@ *.a *.sublime-project *.sublime-workspace -dist/ \ No newline at end of file +dist/ +.DS_Store
diff --git a/cmd/cache.go b/cmd/cache.go index 0a976e5..bbb9c7b 100644 --- a/cmd/cache.go +++ b/cmd/cache.go
@@ -13,15 +13,22 @@ "github.com/Masterminds/cookoo" ) +var cacheEnabled = true + +var errCacheDisabled = errors.New("Cache disabled") + // EnsureCacheDir Creates the $HOME/.glide/cache directory (unless home is // specified to be different) if it does not exist. func EnsureCacheDir(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { home := p.Get("home", "").(string) if home == "" { - return nil, errors.New("No home directory set to create") + cacheEnabled = false + Warn("Unable to locate home directory") + return false, nil } err := os.MkdirAll(filepath.Join(home, "cache", "info"), os.ModeDir|os.ModePerm) if err != nil { + cacheEnabled = false Warn("Error creating Glide directory %s", home) } return false, nil @@ -69,6 +76,9 @@ } func saveCacheRepoData(key string, data cacheRepoInfo, location string) error { + if !cacheEnabled { + return errCacheDisabled + } data.LastUpdate = time.Now().String() d, err := json.Marshal(data) if err != nil { @@ -87,6 +97,9 @@ } func cacheRepoData(key, location string) (*cacheRepoInfo, error) { + if !cacheEnabled { + return &cacheRepoInfo{}, errCacheDisabled + } c := &cacheRepoInfo{} p := filepath.Join(location, "cache", "info", key+".json") f, err := ioutil.ReadFile(p)
diff --git a/cmd/get_imports.go b/cmd/get_imports.go index fa55356..35baee6 100644 --- a/cmd/get_imports.go +++ b/cmd/get_imports.go
@@ -304,7 +304,10 @@ if err == nil { Debug("Saving default branch for %s", repo.Remote()) c := cacheRepoInfo{DefaultBranch: branch} - saveCacheRepoData(key, c, home) + err = saveCacheRepoData(key, c, home) + if err == errCacheDisabled { + Debug("Unable to cache default branch because caching is disabled") + } } } @@ -357,7 +360,9 @@ Debug("Saving default branch for %s", repo.Remote()) c := cacheRepoInfo{DefaultBranch: branch} err = saveCacheRepoData(key, c, home) - if err != nil { + if err == errCacheDisabled { + Debug("Unable to cache default branch because caching is disabled") + } else if err != nil { Debug("Error saving %s to cache. Error: %s", repo.Remote(), err) } } @@ -406,7 +411,9 @@ Debug("Saving default branch for %s", repo.Remote()) c := cacheRepoInfo{DefaultBranch: branch} err = saveCacheRepoData(key, c, home) - if err != nil { + if err == errCacheDisabled { + Debug("Unable to cache default branch because caching is disabled") + } else if err != nil { Debug("Error saving %s to cache. Error: %s", repo.Remote(), err) } } @@ -605,7 +612,6 @@ // Some repos will have multiple branches in them (e.g. Git) while others // (e.g. Svn) will not. -// TODO(mattfarina): Add API calls to github, bitbucket, etc. func defaultBranch(repo v.Repo, home string) string { // Svn and Bzr use different locations (paths or entire locations) @@ -666,7 +672,12 @@ db := gh["default_branch"].(string) if kerr == nil { d.DefaultBranch = db - saveCacheRepoData(key, d, home) + err := saveCacheRepoData(key, d, home) + if err == errCacheDisabled { + Debug("Unable to cache default branch because caching is disabled") + } else if err != nil { + Debug("Error saving %s to cache. Error: %s", repo.Remote(), err) + } } return db } @@ -695,7 +706,12 @@ db := bb["name"].(string) if kerr == nil { d.DefaultBranch = db - saveCacheRepoData(key, d, home) + err := saveCacheRepoData(key, d, home) + if err == errCacheDisabled { + Debug("Unable to cache default branch because caching is disabled") + } else if err != nil { + Debug("Error saving %s to cache. Error: %s", repo.Remote(), err) + } } return db }
diff --git a/cmd/msg.go b/cmd/msg.go index d2f6787..a054cbf 100644 --- a/cmd/msg.go +++ b/cmd/msg.go
@@ -65,9 +65,9 @@ func ErrMsg(msg string, args ...interface{}) { if len(args) == 0 { fmt.Fprint(os.Stderr, msg) - return + } else { + fmt.Fprintf(os.Stderr, msg, args...) } - fmt.Fprintf(os.Stderr, msg, args...) // Get rid of the annoying fact that messages need \n at the end, but do // it in a backward compatible way. @@ -81,9 +81,9 @@ func Msg(msg string, args ...interface{}) { if len(args) == 0 { fmt.Fprint(os.Stderr, msg) - return + } else { + fmt.Fprintf(os.Stderr, msg, args...) } - fmt.Fprintf(os.Stderr, msg, args...) // Get rid of the annoying fact that messages need \n at the end, but do // it in a backward compatible way.