]> git.lizzy.rs Git - go-anidb.git/blobdiff - cache.go
anidb: Don't use a nil fileLock
[go-anidb.git] / cache.go
index 1f1db42ee1dcb75415a535185f8e5f4d495596a3..64cae67f451d6f4845af248635d2b5349befd67c 100644 (file)
--- a/cache.go
+++ b/cache.go
@@ -145,9 +145,10 @@ func (c *cacheDir) Get(v Cacheable, keys ...cacheKey) (err error) {
        defer func() {
                log.Println("Got entry", keys, "(error", err, ")")
        }()
-       flock := lockFile(cachePath(keys...))
-       flock.Lock()
-       defer flock.Unlock()
+       if flock := lockFile(cachePath(keys...)); flock != nil {
+               flock.Lock()
+               defer flock.Unlock()
+       }
 
        fh, err := c.Open(keys...)
        if err != nil {
@@ -230,9 +231,10 @@ func (c *cacheDir) Set(v Cacheable, keys ...cacheKey) (n int64, err error) {
        }
 
        // We have good data, time to actually put it in the cache
-       flock := lockFile(cachePath(keys...))
-       flock.Lock()
-       defer flock.Unlock()
+       if flock := lockFile(cachePath(keys...)); flock != nil {
+               flock.Lock()
+               defer flock.Unlock()
+       }
 
        fh, err := c.Create(keys...)
        if err != nil {