Skip to content

Commit

Permalink
Move fs code to system/ package.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault committed Aug 4, 2024
1 parent 90e9020 commit 922d6bc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 79 deletions.
65 changes: 0 additions & 65 deletions guest/guest.go

This file was deleted.

24 changes: 15 additions & 9 deletions guest/fs.go → system/fs.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package guest
package system

import (
"context"
"io/fs"

"github.com/ipfs/boxo/files"
"github.com/ipfs/boxo/path"
iface "github.com/ipfs/kubo/core/coreiface"
"github.com/pkg/errors"
)
Expand All @@ -20,7 +21,8 @@ var _ fs.FS = (*FS)(nil)
// [testing/fstest.TestFS] may be used to test implementations of an FS for
// correctness.
type FS struct {
IPFS iface.CoreAPI
API iface.UnixfsAPI
Path path.Path
}

// Open opens the named file.
Expand All @@ -33,20 +35,24 @@ type FS struct {
// fs.ValidPath(name), returning a *fs.PathError with Err set to
// fs.ErrInvalid or fs.ErrNotExist.
func (f FS) Open(name string) (fs.File, error) {
if !fs.ValidPath(name) {
p, err := path.Join(f.Path, name)
if err != nil {
return nil, &fs.PathError{
Op: "FS.Open",
Op: "path.Join",
Path: name,
Err: errors.New("invalid path"),
Err: err,
}
}

path, err := f.IPFS.Name().Resolve(context.TODO(), name)
if err != nil {
return nil, err
if !fs.ValidPath(p.String()) {
return nil, &fs.PathError{
Op: "fs.ValidPath",
Path: name,
Err: errors.New("invalid path"),
}
}

node, err := f.IPFS.Unixfs().Get(context.TODO(), path)
node, err := f.API.Get(context.TODO(), p)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions guest/fs_test.go → system/fs_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package guest_test
package system_test

import (
"testing"
"testing/fstest"

"github.com/stretchr/testify/require"
"github.com/wetware/go/guest"
"github.com/wetware/go/system"
)

func TestFS(t *testing.T) {
t.Parallel()

err := fstest.TestFS(guest.FS{})
err := fstest.TestFS(system.FS{})
require.NoError(t, err)
}
4 changes: 2 additions & 2 deletions ww.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"github.com/thejerf/suture/v4"
"github.com/wetware/go/guest"
"github.com/wetware/go/system"
)

const Proto = "/ww/0.0.0"
Expand Down Expand Up @@ -103,7 +103,7 @@ func (c Cluster) Serve(ctx context.Context) error {
// WithSysWalltime().
// WithWalltime().
WithStartFunctions().
WithFS(guest.FS{IPFS: c.IPFS}).
WithFS(system.FS{API: c.IPFS.Unixfs()}).
WithRandSource(rand.Reader).
WithStdin(os.Stdin).
WithStderr(os.Stderr).
Expand Down

0 comments on commit 922d6bc

Please sign in to comment.