Skip to content

Commit

Permalink
chore: respect XDG_CACHE_HOME (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guanran928 authored Nov 1, 2023
1 parent de25f01 commit 81ca28e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,27 @@ 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
}

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")
Expand Down

0 comments on commit 81ca28e

Please sign in to comment.