From a2f7950f63a5e3a5679f6b8aa468c158b160c7e5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 20 Jun 2013 12:37:17 -0700 Subject: [PATCH] Make sure the cache dir is absolute --- packer.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packer.go b/packer.go index a4662eb57..056c8b003 100644 --- a/packer.go +++ b/packer.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "log" "os" + "path/filepath" "runtime" ) @@ -34,13 +35,17 @@ func main() { log.Printf("Packer config: %+v", config) - defer plugin.CleanupClients() - cacheDir := os.Getenv("PACKER_CACHE_DIR") if cacheDir == "" { cacheDir = "packer_cache" } + cacheDir, err = filepath.Abs(cacheDir) + if err != nil { + fmt.Fprintf(os.Stderr, "Error preparing cache directory: \n\n%s\n", err) + os.Exit(1) + } + if err := os.MkdirAll(cacheDir, 0755); err != nil { fmt.Fprintf(os.Stderr, "Error preparing cache directory: \n\n%s\n", err) os.Exit(1) @@ -49,6 +54,8 @@ func main() { log.Printf("Setting cache directory: %s", cacheDir) cache := &packer.FileCache{CacheDir: cacheDir} + defer plugin.CleanupClients() + envConfig := packer.DefaultEnvironmentConfig() envConfig.Cache = cache envConfig.Commands = config.CommandNames()