core: cache makes proper path with slashes after "." [GH-716]
This commit is contained in:
parent
74f018df2b
commit
629f3eee21
|
@ -46,6 +46,8 @@ BUG FIXES:
|
||||||
|
|
||||||
* core: No colored output in machine-readable output. [GH-684]
|
* core: No colored output in machine-readable output. [GH-684]
|
||||||
* core: User variables can now be used for non-string fields. [GH-598]
|
* core: User variables can now be used for non-string fields. [GH-598]
|
||||||
|
* core: Fix bad download paths if the download URL contained a "."
|
||||||
|
before a "/" [GH-716]
|
||||||
* builder/virtualbox: don't download guest additions if disabled. [GH-731]
|
* builder/virtualbox: don't download guest additions if disabled. [GH-731]
|
||||||
* post-processor/vsphere: Uploads VM properly. [GH-694]
|
* post-processor/vsphere: Uploads VM properly. [GH-694]
|
||||||
* post-processor/vsphere: Process user variables.
|
* post-processor/vsphere: Process user variables.
|
||||||
|
|
|
@ -72,15 +72,16 @@ func (f *FileCache) RUnlock(key string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FileCache) cachePath(key string, hashKey string) string {
|
func (f *FileCache) cachePath(key string, hashKey string) string {
|
||||||
suffix := ""
|
if endIndex := strings.Index(key, "?"); endIndex > -1 {
|
||||||
endIndex := strings.Index(key, "?")
|
key = key[:endIndex]
|
||||||
if endIndex == -1 {
|
|
||||||
endIndex = len(key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dotIndex := strings.LastIndex(key[0:endIndex], ".")
|
suffix := ""
|
||||||
|
dotIndex := strings.LastIndex(key, ".")
|
||||||
if dotIndex > -1 {
|
if dotIndex > -1 {
|
||||||
suffix = key[dotIndex:endIndex]
|
if slashIndex := strings.LastIndex(key, "/"); slashIndex <= dotIndex {
|
||||||
|
suffix = key[dotIndex:]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return filepath.Join(f.CacheDir, hashKey+suffix)
|
return filepath.Join(f.CacheDir, hashKey+suffix)
|
||||||
|
|
|
@ -37,12 +37,22 @@ func TestFileCache(t *testing.T) {
|
||||||
defer os.RemoveAll(cacheDir)
|
defer os.RemoveAll(cacheDir)
|
||||||
|
|
||||||
cache := &FileCache{CacheDir: cacheDir}
|
cache := &FileCache{CacheDir: cacheDir}
|
||||||
path := cache.Lock("foo.ext?foo=bar.foo")
|
|
||||||
|
// Test path with no extension (GH-716)
|
||||||
|
path := cache.Lock("/foo.bar/baz")
|
||||||
|
defer cache.Unlock("/foo.bar/baz")
|
||||||
|
if strings.Contains(path, ".bar") {
|
||||||
|
t.Fatalf("bad: %s", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test paths with a ?
|
||||||
|
path = cache.Lock("foo.ext?foo=bar.foo")
|
||||||
defer cache.Unlock("foo.ext?foo=bar.foo")
|
defer cache.Unlock("foo.ext?foo=bar.foo")
|
||||||
if !strings.HasSuffix(path, ".ext") {
|
if !strings.HasSuffix(path, ".ext") {
|
||||||
t.Fatalf("bad extension with question mark: %s", path)
|
t.Fatalf("bad extension with question mark: %s", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test normal paths
|
||||||
path = cache.Lock("foo.iso")
|
path = cache.Lock("foo.iso")
|
||||||
if !strings.HasSuffix(path, ".iso") {
|
if !strings.HasSuffix(path, ".iso") {
|
||||||
t.Fatalf("path doesn't end with suffix '%s': '%s'", ".iso", path)
|
t.Fatalf("path doesn't end with suffix '%s': '%s'", ".iso", path)
|
||||||
|
|
Loading…
Reference in New Issue