shared/cache/cache.go (view raw)
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 | package cache
import (
"os"
"path/filepath"
"alin.ovh/homestead/shared/file"
)
var (
home string
Root *os.Root
)
func init() {
var err error
home, err = os.UserCacheDir()
if err != nil {
panic("could not determine user cache directory: " + err.Error())
}
dir := filepath.Join(home, "homestead")
if !file.Exists(dir) {
err = os.MkdirAll(dir, 0o750)
if err != nil {
panic("could not create cache sub-directory: " + err.Error())
}
}
Root, err = os.OpenRoot(dir)
if err != nil {
panic("could not open cache sub-directory: " + err.Error())
}
}
func JoinPath(path string) string {
return filepath.Join(Root.Name(), path)
}
|