filecache: include GOOS/GOARCH in the key (#772)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ type fileReadCloser struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fc *fileCache) path(key Key) string {
|
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) {
|
func (fc *fileCache) Get(key Key) (content io.ReadCloser, ok bool, err error) {
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ package compilationcache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/tetratelabs/wazero/internal/testing/require"
|
"github.com/tetratelabs/wazero/internal/testing/require"
|
||||||
@@ -133,3 +136,11 @@ func TestFileCache_Get(t *testing.T) {
|
|||||||
require.False(t, ok)
|
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"))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user