core: Create cache directory only when needed [GH-367]

This commit is contained in:
Mitchell Hashimoto 2014-04-26 20:33:12 -07:00
parent 9365b879c0
commit 9ef50487fb
3 changed files with 10 additions and 5 deletions

View File

@ -34,6 +34,7 @@ BUG FIXES:
* core: Errors are properly shown when adding bad floppy files. [GH-1043]
* core: Fix some URL parsing issues on Windows.
* core: Create Cache directory only when it is needed. [GH-367]
* builder/amazon-instance: Use S3Endpoint for ec2-upload-bundle arg,
which works for every region. [GH-904]
* builder/digitalocean: updated default image_id [GH-1032]

View File

@ -106,11 +106,6 @@ func wrappedMain() int {
return 1
}
if err := os.MkdirAll(cacheDir, 0755); err != nil {
fmt.Fprintf(os.Stderr, "Error preparing cache directory: \n\n%s\n", err)
return 1
}
log.Printf("Setting cache directory: %s", cacheDir)
cache := &packer.FileCache{CacheDir: cacheDir}

View File

@ -3,6 +3,8 @@ package packer
import (
"crypto/sha256"
"encoding/hex"
"log"
"os"
"path/filepath"
"strings"
"sync"
@ -84,6 +86,13 @@ func (f *FileCache) cachePath(key string, hashKey string) string {
}
}
// Make the cache directory. We ignore errors here, but
// log them in case something happens.
if err := os.MkdirAll(f.CacheDir, 0755); err != nil {
log.Printf(
"[ERR] Error making cacheDir: %s %s", f.CacheDir, err)
}
return filepath.Join(f.CacheDir, hashKey+suffix)
}