package cache import ( "os" "path/filepath" "go.alanpearce.eu/homestead/internal/file" ) var home string var 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) }