return
}
- if err = os.Chtimes(cd.cachePath(key...), time.Now(), time.Now()); err == nil {
+ if err = cd.ChtimeNoLock(time.Now(), key...); err == nil {
return
}
}
return fh.Close()
}
+
+// Same as Chtime, but does not try to acquire a file lock on the file
+// before. Only call this if you already hold a lock to the file.
+func (cd *CacheDir) ChtimeNoLock(t time.Time, key ...CacheKey) (err error) {
+ return os.Chtimes(cd.cachePath(key...), time.Now(), t)
+}
+
+// Sets the mtime of the file backing the given key to the specified time.
+func (cd *CacheDir) Chtime(t time.Time, key ...CacheKey) (err error) {
+ lock, err := cd.Lock(key...)
+ if err != nil {
+ return
+ }
+ defer lock.Unlock()
+
+ return cd.ChtimeNoLock(t, key...)
+}