// On a list of CacheKeys, the last component is taken to represent a file
// and all the other components represent the intermediary directories.
// This means that it's not possible to have subkeys of an existing file key.
+//
+// NOTE: when running on Windows, directories that start with a '.' get the
+// '.' replaced by a '_'. This is because regular Windows tools can't deal
+// with directories starting with a dot.
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 {
+func Stringify(stuff ...CacheKey) []string {
ret := make([]string, len(stuff))
for i := range stuff {
s := fmt.Sprint(stuff[i])
// This also means that cache keys that are file-backed
// cannot have subkeys.
func (cd *CacheDir) cachePath(key ...CacheKey) string {
- parts := append([]string{cd.GetCacheDir()}, stringify(key...)...)
+ parts := append([]string{cd.GetCacheDir()}, Stringify(key...)...)
p := filepath.Join(filterDots(parts...)...)
return p
}
func (cd *CacheDir) GetInvalid(key ...CacheKey) (ts time.Time) {
invKey := append(invalidPath, key...)
- stat, _ := cd.Stat(invKey...)
- return stat.ModTime()
+ if stat, err := cd.Stat(invKey...); err == nil {
+ ts = stat.ModTime()
+ }
+ return
}
// Checks if the given key is not marked as invalid, or if it is,