From 6072b05d3b721bcc594b0afa26ffcc0870188684 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 20 Jul 2013 16:53:55 -0700 Subject: [PATCH] packer: Extension works properly with URLs too /cc @sit --- packer/cache.go | 5 +++++ packer/cache_test.go | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packer/cache.go b/packer/cache.go index 91fd92593..ae0c2ef6b 100644 --- a/packer/cache.go +++ b/packer/cache.go @@ -76,6 +76,11 @@ func (f *FileCache) cachePath(key string, hashKey string) string { dotIndex := strings.LastIndex(key, ".") if dotIndex > -1 { suffix = key[dotIndex:len(key)] + + idx := strings.Index(suffix, "?") + if idx != -1 { + suffix = suffix[0:idx] + } } return filepath.Join(f.CacheDir, hashKey+suffix) diff --git a/packer/cache_test.go b/packer/cache_test.go index 3d2ac70dc..2d76edee5 100644 --- a/packer/cache_test.go +++ b/packer/cache_test.go @@ -37,8 +37,13 @@ func TestFileCache(t *testing.T) { defer os.RemoveAll(cacheDir) cache := &FileCache{CacheDir: cacheDir} - path := cache.Lock("foo.iso") + path := cache.Lock("foo.ext?foo=bar") + defer cache.Unlock("foo.ext?foo=bar") + if !strings.HasSuffix(path, ".ext") { + t.Fatalf("bad extension with question mark: %s", path) + } + path = cache.Lock("foo.iso") if !strings.HasSuffix(path, ".iso") { t.Fatalf("path doesn't end with suffix '%s': '%s'", ".iso", path) }