Commit 1bd9288c authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Use strings operations, faster than regexp and easy

/cc @sit
parent d999d1c5
......@@ -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)
}
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment