packer: Extension works properly with URLs too

/cc @sit
This commit is contained in:
Mitchell Hashimoto 2013-07-20 16:53:55 -07:00
parent 1bd9288c5f
commit 6072b05d3b
2 changed files with 11 additions and 1 deletions

View File

@ -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)

View File

@ -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)
}