From faf881753083a7dd6e1117bff909dbfb86f02dcf Mon Sep 17 00:00:00 2001 From: John Starich Date: Tue, 27 Jul 2021 22:46:05 -0500 Subject: [PATCH] Fix non-JS tests --- internal/fs/fs.go | 2 +- internal/fs/fs_js.go | 6 ++++++ internal/fs/fs_other.go | 22 ++++++++++++++++++++-- internal/fs/read.go | 3 +-- internal/tarfs/fs.go | 20 ++++++++------------ internal/tarfs/fs_test.go | 2 +- 6 files changed, 37 insertions(+), 18 deletions(-) diff --git a/internal/fs/fs.go b/internal/fs/fs.go index 63ffb58..9cfbbfe 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -86,7 +86,7 @@ func OverlayTarGzip(mountPath string, r io.ReadCloser, persist bool, shouldCache }, } - _, err = underlyingFS.Stat(tarfsDoneMarker) + _, err = hackpadfs.Stat(underlyingFS, tarfsDoneMarker) if err == nil { // tarfs already completed successfully and is persisted, // so close tarfs reader and mount the existing files diff --git a/internal/fs/fs_js.go b/internal/fs/fs_js.go index 78b6b7c..526ab9b 100644 --- a/internal/fs/fs_js.go +++ b/internal/fs/fs_js.go @@ -7,6 +7,8 @@ import ( "github.com/hack-pad/go-indexeddb/idb" "github.com/hack-pad/hackpadfs/indexeddb" + "github.com/hack-pad/hackpadfs/indexeddb/idbblob" + "github.com/hack-pad/hackpadfs/keyvalue/blob" ) type persistFs struct { @@ -23,3 +25,7 @@ func newPersistDB(name string, relaxedDurability bool, shouldCache ShouldCacher) }) return &persistFs{fs}, err } + +func newBlobLength(i int) (blob.Blob, error) { + return idbblob.NewLength(i) +} diff --git a/internal/fs/fs_other.go b/internal/fs/fs_other.go index c51cb98..c3d5b35 100644 --- a/internal/fs/fs_other.go +++ b/internal/fs/fs_other.go @@ -2,14 +2,32 @@ package fs -type persistFs struct { +import ( + "context" + + "github.com/hack-pad/hackpadfs" + "github.com/hack-pad/hackpadfs/keyvalue/blob" +) + +type persistFsInterface interface { hackpadfs.FS + hackpadfs.ChmodFS + hackpadfs.MkdirFS + hackpadfs.OpenFileFS +} + +type persistFs struct { + persistFsInterface } func newPersistDB(name string, relaxedDurability bool, shouldCache ShouldCacher) (*persistFs, error) { panic("not implemented") } -func (p *persistFs) Clear() error { +func (p *persistFs) Clear(context.Context) error { panic("not implemented") } + +func newBlobLength(i int) (blob.Blob, error) { + return blob.NewBytesLength(i), nil +} diff --git a/internal/fs/read.go b/internal/fs/read.go index 66e34f9..9eaa7d1 100644 --- a/internal/fs/read.go +++ b/internal/fs/read.go @@ -4,7 +4,6 @@ import ( "io" "github.com/hack-pad/hackpadfs" - "github.com/hack-pad/hackpadfs/indexeddb/idbblob" "github.com/hack-pad/hackpadfs/keyvalue/blob" "github.com/johnstarich/go-wasm/internal/interop" ) @@ -51,7 +50,7 @@ func (f *FileDescriptors) ReadFile(path string) (blob.Blob, error) { return nil, err } - buf, err := idbblob.NewLength(int(info.Size())) + buf, err := newBlobLength(int(info.Size())) if err != nil { return nil, err } diff --git a/internal/tarfs/fs.go b/internal/tarfs/fs.go index c4b0d6f..6777130 100644 --- a/internal/tarfs/fs.go +++ b/internal/tarfs/fs.go @@ -12,7 +12,6 @@ import ( "github.com/hack-pad/hackpadfs" "github.com/johnstarich/go-wasm/internal/bufferpool" "github.com/johnstarich/go-wasm/internal/common" - "github.com/johnstarich/go-wasm/internal/fsutil" "github.com/johnstarich/go-wasm/internal/pubsub" "github.com/johnstarich/go-wasm/log" "github.com/pkg/errors" @@ -252,18 +251,15 @@ func (f fullReader) Read(p []byte) (n int, err error) { return } -func (fs *FS) ensurePath(path string) (normalizedPath string, err error) { - path = fsutil.NormalizePath(path) - fs.ps.Wait(path) - return path, fs.initErr -} - -func (fs *FS) Open(path string) (hackpadfs.File, error) { - path, err := fs.ensurePath(path) - if err != nil { - return nil, err +func (fs *FS) Open(name string) (hackpadfs.File, error) { + if !hackpadfs.ValidPath(name) { + return nil, &hackpadfs.PathError{Op: "open", Path: name, Err: hackpadfs.ErrInvalid} + } + fs.ps.Wait(name) + if fs.initErr != nil { + return nil, &hackpadfs.PathError{Op: "open", Path: name, Err: fs.initErr} } - return fs.underlyingFS.Open(path) + return fs.underlyingFS.Open(name) } func (fs *FS) Done() <-chan struct{} { diff --git a/internal/tarfs/fs_test.go b/internal/tarfs/fs_test.go index 2278888..d791e9f 100644 --- a/internal/tarfs/fs_test.go +++ b/internal/tarfs/fs_test.go @@ -52,7 +52,7 @@ func buildTarFromFS(src hackpadfs.FS) (io.Reader, error) { archive := tar.NewWriter(compressor) defer archive.Close() - err := hackpadfs.WalkDir(src, "/", copyTarWalk(src, archive)) + err := hackpadfs.WalkDir(src, ".", copyTarWalk(src, archive)) return &buf, errors.Wrap(err, "Failed building tar from FS walk") }