- return nil
-}
-
-// Returns the current cache dir.
-func GetCacheDir() (path string) {
- cache.RLock()
- defer cache.RUnlock()
-
- return cache.CacheDir
-}
-
-type cacheKey interface{}
-
-// All "bad characters" that can't go in Windows paths.
-// It's a superset of the "bad characters" on other OSes, so this works.
-var badPath = regexp.MustCompile(`[\\/:\*\?\"<>\|]`)
-
-func stringify(stuff ...cacheKey) []string {
- ret := make([]string, len(stuff))
- for i := range stuff {
- s := fmt.Sprint(stuff[i])
- ret[i] = badPath.ReplaceAllLiteralString(s, "_")
- }
- return ret
-}
-
-// Each key but the last is treated as a directory.
-// The last key is treated as a regular file.
-//
-// This also means that cache keys that are file-backed
-// cannot have subkeys.
-func cachePath(keys ...cacheKey) string {
- parts := append([]string{GetCacheDir()}, stringify(keys...)...)
- p := path.Join(parts...)
- return p
-}
-
-// Opens the file that backs the specified keys.
-func (c *cacheDir) Open(keys ...cacheKey) (fh *os.File, err error) {
- subItem := cachePath(keys...)
- return os.Open(subItem)