summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-11-21 09:16:23 +0800
committerEltrac <hi@guhub.cn>2025-11-21 09:16:23 +0800
commit0f18c94faa70942698c9904e79d0985464458604 (patch)
tree2c249167e56dba8191e18c1e520e05d46c667b8b
parentcf0d0e15faeabbdfa79caec505cf4ac31488eb56 (diff)
perf: write timestamp to cache file instead of relying on mtime
-rw-r--r--brewcheck.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/brewcheck.go b/brewcheck.go
index ac34786..d550db4 100644
--- a/brewcheck.go
+++ b/brewcheck.go
@@ -17,10 +17,10 @@ func EnsureBrewAvailable() {
cache := filepath.Join(xdg.CacheHome, "wthis", "brew-checked")
// 1. check if cache file exists and is fresh
- if info, err := os.Stat(cache); err == nil {
- if time.Since(info.ModTime()) < TTL {
- return // recently verified that brew exists
- }
+ data, _ := os.ReadFile(cache)
+ t, _ := time.Parse(time.RFC3339, string(data))
+ if time.Since(t) < TTL {
+ return
}
// 2. otherwise, actually check
@@ -33,5 +33,5 @@ func EnsureBrewAvailable() {
// 3. write cache
_ = os.MkdirAll(filepath.Dir(cache), 0o755)
- _ = os.WriteFile(cache, []byte{}, 0o644)
+ _ = os.WriteFile(cache, []byte(time.Now().Format(time.RFC3339)), 0o644)
}