Skip to content

Commit

Permalink
Fix non-JS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnStarich committed Jul 28, 2021
1 parent 96a77b2 commit faf8817
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions internal/fs/fs_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
22 changes: 20 additions & 2 deletions internal/fs/fs_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions internal/fs/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down
20 changes: 8 additions & 12 deletions internal/tarfs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{} {
Expand Down
2 changes: 1 addition & 1 deletion internal/tarfs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit faf8817

Please sign in to comment.