filecache: include GOOS/GOARCH in the key (#772)

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
Takeshi Yoneda
2022-08-29 10:55:57 +09:00
committed by GitHub
parent 777baf1842
commit be09f7fea0
2 changed files with 13 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import (
"io"
"os"
"path"
"runtime"
"sync"
)
@@ -40,7 +41,7 @@ type fileReadCloser struct {
}
func (fc *fileCache) path(key Key) string {
return path.Join(fc.dirPath, hex.EncodeToString(key[:]))
return path.Join(fc.dirPath, runtime.GOARCH+"-"+runtime.GOOS+"-"+hex.EncodeToString(key[:]))
}
func (fc *fileCache) Get(key Key) (content io.ReadCloser, ok bool, err error) {

View File

@@ -2,8 +2,11 @@ package compilationcache
import (
"bytes"
"fmt"
"io"
"os"
"runtime"
"strings"
"testing"
"github.com/tetratelabs/wazero/internal/testing/require"
@@ -133,3 +136,11 @@ func TestFileCache_Get(t *testing.T) {
require.False(t, ok)
})
}
func TestFileCache_path(t *testing.T) {
fc := &fileCache{dirPath: "/tmp/.wazero"}
actual := fc.path(Key{1, 2, 3, 4, 5})
require.Contains(t, actual, fmt.Sprintf("%s-%s-", runtime.GOARCH, runtime.GOOS))
require.True(t, strings.HasPrefix(actual, fc.dirPath))
require.True(t, strings.HasSuffix(actual, "0102030405000000000000000000000000000000000000000000000000000000"))
}