packer: Use strings operations, faster than regexp and easy

/cc @sit
This commit is contained in:
Mitchell Hashimoto
2013-07-20 16:50:18 -07:00
parent 9349c81631
commit cf9bc2c819
2 changed files with 6 additions and 5 deletions
+5 -5
View File
@@ -4,7 +4,7 @@ import (
"crypto/sha256"
"encoding/hex"
"path/filepath"
"regexp"
"strings"
"sync"
)
@@ -72,12 +72,12 @@ func (f *FileCache) RUnlock(key string) {
}
func (f *FileCache) cachePath(key string, hashKey string) string {
var suffixPattern = regexp.MustCompile(`(\.\w+)$`)
matches := suffixPattern.FindStringSubmatch(key)
suffix := ""
if matches != nil {
suffix = matches[0]
dotIndex := strings.LastIndex(key, ".")
if dotIndex > -1 {
suffix = key[dotIndex:len(key)]
}
return filepath.Join(f.CacheDir, hashKey+suffix)
}
+1
View File
@@ -42,6 +42,7 @@ func TestFileCache(t *testing.T) {
if !strings.HasSuffix(path, ".iso") {
t.Fatalf("path doesn't end with suffix '%s': '%s'", ".iso", path)
}
err = ioutil.WriteFile(path, []byte("data"), 0666)
if err != nil {
t.Fatalf("error writing: %s", err)