From 81ca28ed694bf7996677ff42bafc5658d2cfe6d6 Mon Sep 17 00:00:00 2001 From: Guanran928 <68757440+Guanran928@users.noreply.github.com> Date: Wed, 1 Nov 2023 20:43:11 +0800 Subject: [PATCH] chore: respect XDG_CACHE_HOME (#32) --- lib/cache.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/cache.go b/lib/cache.go index 08e1f9c..c7389f6 100644 --- a/lib/cache.go +++ b/lib/cache.go @@ -106,8 +106,13 @@ func ClearCahceFiles() { func getDictDir() string { dbDir := os.Getenv("YDICT_DB") + xdgCacheDir := os.Getenv("XDG_CACHE_HOME") if dbDir == "" { - dbDir = filepath.Join(os.Getenv("HOME"), ".ydict") + if xdgCacheDir != "" { + dbDir = filepath.Join(xdgCacheDir, "ydict") + } else { + dbDir = filepath.Join(os.Getenv("HOME"), ".cache/ydict") + } } return dbDir @@ -115,8 +120,13 @@ func getDictDir() string { func getDictDBDir() string { dbDir := os.Getenv("YDICT_DB") + xdgCacheDir := os.Getenv("XDG_CACHE_HOME") if dbDir == "" { - dbDir = filepath.Join(os.Getenv("HOME"), ".ydict") + if xdgCacheDir != "" { + dbDir = filepath.Join(xdgCacheDir, "ydict") + } else { + dbDir = filepath.Join(os.Getenv("HOME"), ".cache/ydict") + } } ydictDir := filepath.Join(dbDir, "db")