]> git.lizzy.rs Git - go-fscache.git/blobdiff - cachekey.go
Replace obsolete lock package
[go-fscache.git] / cachekey.go
index 3c489caef22965033de2c1a1ce01a147e60ec5bd..8d8725d811dd700cd8538bece62edaa6ea67fcff 100755 (executable)
@@ -16,13 +16,17 @@ import (
 // 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])
@@ -37,7 +41,7 @@ func stringify(stuff ...CacheKey) []string {
 // 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
 }
@@ -50,8 +54,10 @@ var invalidPath = []CacheKey{".invalid"}
 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,