diff --git a/file-util.go b/file-util.go index 7dde39f..85b0208 100644 --- a/file-util.go +++ b/file-util.go @@ -111,12 +111,12 @@ var ModelUrls map[string]string = map[string]string{ // // CachedPath does several things consequently: // 1. Resolves input string to a fullpath cached filename candidate. -// 2. Check it at `CachePath`, if exists, then return the candidate. If not -// 3. Retrieves and Caches data to `CachePath` and returns path to cached data +// 2. Check it at `CachedDir`, if exists, then return the candidate. If not +// 3. Retrieves and Caches data to `CachedDir` and returns path to cached data func CachedPath(filenameOrUrl string) (resolvedPath string, err error) { filename := path.Base(filenameOrUrl) - // Resolves to "candidate" filename at `CacheDir` - cachedFileCandidate := fmt.Sprintf("%s/%s", CacheDir, filename) + // Resolves to "candidate" filename at `CachedDir` + cachedFileCandidate := fmt.Sprintf("%s/%s", CachedDir, filename) // 1. Cached candidate file exists if _, err := os.Stat(cachedFileCandidate); err == nil { @@ -288,9 +288,9 @@ func copyFile(src, dst string) error { return err } -// CleanCache removes all files cached at `CacheDir` +// CleanCache removes all files cached at `CachedDir` func CleanCache() error { - err := os.RemoveAll(CacheDir) + err := os.RemoveAll(CachedDir) if err != nil { err = fmt.Errorf("CleanCache() failed: %w", err) return err diff --git a/init.go b/init.go index 1b2f0d9..71466a2 100644 --- a/init.go +++ b/init.go @@ -7,13 +7,13 @@ import ( ) var ( - CacheDir string = "NOT_SETTING" + CachedDir string = "NOT_SETTING" gotchEnvKey string = "GOTCH_CACHE" ) func init() { homeDir := os.Getenv("HOME") - CacheDir = fmt.Sprintf("%s/.cache/gotch", homeDir) // default dir: "{$HOME}/.cache/gotch" + CachedDir = fmt.Sprintf("%s/.cache/gotch", homeDir) // default dir: "{$HOME}/.cache/gotch" initEnv() // log.Printf("INFO: CacheDir=%q\n", CacheDir) @@ -22,11 +22,11 @@ func init() { func initEnv() { val := os.Getenv(gotchEnvKey) if val != "" { - CacheDir = val + CachedDir = val } - if _, err := os.Stat(CacheDir); os.IsNotExist(err) { - if err := os.MkdirAll(CacheDir, 0755); err != nil { + if _, err := os.Stat(CachedDir); os.IsNotExist(err) { + if err := os.MkdirAll(CachedDir, 0755); err != nil { log.Fatal(err) } }