@@ -5,16 +5,12 @@ import (
55 "path/filepath"
66)
77
8- var DefaultCacheDir = "packer_cache"
9-
108// CachePath returns an absolute path to a cache file or directory
119//
12- // When the directory is not absolute, CachePath will try to get
13- // current working directory to be able to return a full path.
14- // CachePath tries to create the resulting path if it doesn't exist.
15- //
16- // CachePath can error in case it cannot find the cwd.
10+ // When the directory is not absolute, CachePath will try to make a
11+ // a cache depending on the operating system.
1712//
13+ // NOTE: cache directory will change depending on operating system dependent
1814// ex:
1915// PACKER_CACHE_DIR="" CacheDir() => "./packer_cache/
2016// PACKER_CACHE_DIR="" CacheDir("foo") => "./packer_cache/foo
@@ -25,11 +21,15 @@ func CachePath(paths ...string) (path string, err error) {
2521 // create the dir based on return path if it doesn't exist
2622 os .MkdirAll (filepath .Dir (path ), os .ModePerm )
2723 }()
28- cacheDir := DefaultCacheDir
24+ cacheDir := getDefaultCacheDir ()
2925 if cd := os .Getenv ("PACKER_CACHE_DIR" ); cd != "" {
3026 cacheDir = cd
3127 }
3228
3329 paths = append ([]string {cacheDir }, paths ... )
34- return filepath .Abs (filepath .Join (paths ... ))
30+ result , err := filepath .Abs (filepath .Join (paths ... ))
31+ if err != nil {
32+ return "" , err
33+ }
34+ return result , err
3535}
0 commit comments