Skip to content

Instantly share code, notes, and snippets.

@akutz
Last active September 20, 2016 16:58
Show Gist options
  • Save akutz/071a275ffb1ffae37f7c742b0b6231af to your computer and use it in GitHub Desktop.
Save akutz/071a275ffb1ffae37f7c742b0b6231af to your computer and use it in GitHub Desktop.
// CachePath returns the path to a cached dependency's sources.
func CachePath(importPath string) {
if importPath == "" {
msg.Die("Missing import path")
}
cache.SystemLock()
base := "."
// Ensure GOPATH
EnsureGopath()
EnsureVendorDir()
EnsureConfig()
// Load lockfile
lock, err := cfg.ReadLockFile(filepath.Join(base, gpath.LockFile))
if err != nil {
msg.Die("Could not load lockfile.")
}
var importedLock *cfg.Lock
for _, l := range lock.Imports {
if strings.EqualFold(importPath, l.Name) {
importedLock = l
break
}
}
if importedLock == nil {
msg.Die("Could not locate import path")
}
repoURL := importedLock.Repository
if repoURL == "" {
repoURL = fmt.Sprintf("https://%s", importedLock.Name)
}
cacheKey, err := cache.Key(repoURL)
if err != nil {
msg.Die("Could not find cache for import path", err)
}
if cacheKey == "" {
msg.Die("Could not find cache for import path")
}
msg.Puts(path.Join(cache.Location(), "src", cacheKey))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment