]> git.lizzy.rs Git - go-fscache.git/blobdiff - cachekey.go
Replace obsolete lock package
[go-fscache.git] / cachekey.go
index 7d059dafd6af6e7021eba048c606ed80c42e80d7..8d8725d811dd700cd8538bece62edaa6ea67fcff 100755 (executable)
@@ -26,7 +26,7 @@ type CacheKey interface{}
 // 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])
@@ -41,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
 }
@@ -54,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,