forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.go
More file actions
47 lines (43 loc) · 1.08 KB
/
cache.go
File metadata and controls
47 lines (43 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cache
import (
"fmt"
"os"
"path/filepath"
)
// The cache directory defaults to os.UserCacheDir(). This location can be
// overridden by the SQLCCACHE environment variable.
//
// Currently the cache stores two types of data: plugins and query analysis
func Dir() (string, error) {
cache := os.Getenv("SQLCCACHE")
if cache != "" {
return cache, nil
}
cacheHome, err := os.UserCacheDir()
if err != nil {
return "", err
}
return filepath.Join(cacheHome, "sqlc"), nil
}
func PluginsDir() (string, error) {
cacheRoot, err := Dir()
if err != nil {
return "", err
}
dir := filepath.Join(cacheRoot, "plugins")
if err := os.MkdirAll(dir, 0755); err != nil && !os.IsExist(err) {
return "", fmt.Errorf("failed to create %s directory: %w", dir, err)
}
return dir, nil
}
func AnalysisDir() (string, error) {
cacheRoot, err := Dir()
if err != nil {
return "", err
}
dir := filepath.Join(cacheRoot, "query_analysis")
if err := os.MkdirAll(dir, 0755); err != nil && !os.IsExist(err) {
return "", fmt.Errorf("failed to create %s directory: %w", dir, err)
}
return dir, nil
}