-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.go
54 lines (45 loc) · 963 Bytes
/
cache.go
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
48
49
50
51
52
53
54
package vin
import (
"os"
"path/filepath"
"strings"
"github.com/skmatz/vin/cache"
)
func (v *Vin) CacheDir() (string, error) {
cache, err := os.UserCacheDir()
if err != nil {
return "", err
}
return filepath.Join(cache, "vin"), nil
}
var repoReplacer = strings.NewReplacer("/", "---")
func (v *Vin) AppAlreadyInstalled(app App) (bool, error) {
cacheDir, err := v.CacheDir()
if err != nil {
return false, err
}
c := cache.New(cacheDir)
key := repoReplacer.Replace(app.Repo)
value := c.GetString(key)
tag, err := app.TagName()
if err != nil {
return false, err
}
return value == tag, nil
}
func (v *Vin) SaveCache(app App) error {
cacheDir, err := v.CacheDir()
if err != nil {
return err
}
if err := os.MkdirAll(cacheDir, os.ModePerm); err != nil {
return err
}
c := cache.New(cacheDir)
key := repoReplacer.Replace(app.Repo)
value, err := app.TagName()
if err != nil {
return err
}
return c.SetString(key, value)
}