Skip to content

Commit

Permalink
change MFS root reference
Browse files Browse the repository at this point in the history
  • Loading branch information
djdv committed Oct 25, 2019
1 parent fa9b1bc commit 89735e3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions plugin/plugins/filesystem/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func TestAll(t *testing.T) {
t.Run("RootFS", func(t *testing.T) { testRootFS(ctx, t, core) })
t.Run("PinFS", func(t *testing.T) { testPinFS(ctx, t, core) })
t.Run("IPFS", func(t *testing.T) { testIPFS(ctx, t, core) })
t.Run("MFS", func(t *testing.T) { testMFS(ctx, t, core) })
t.Run("IPNS", func(t *testing.T) { testIPNS(ctx, t, core) })

pluginEnv := &plugin.Environment{Config: defaultConfig()}
t.Run("Plugin", func(t *testing.T) { testPlugin(t, pluginEnv, core) })
Expand Down
4 changes: 2 additions & 2 deletions plugin/plugins/filesystem/mfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"testing"

fsnodes "github.com/ipfs/go-ipfs/plugin/plugins/filesystem/nodes"
coreiface "github.com/ipfs/interface-go-ipfs-core"
)

func testMFS(ctx context.Context, t *testing.T, core coreiface.CoreAPI) {
t.Run("Baseline", func(t *testing.T) { baseLine(ctx, t, core, fsnodes.MFSAttacher) })
//TODO: init root CID
//t.Run("Baseline", func(t *testing.T) { baseLine(ctx, t, core, fsnodes.MFSAttacher) })
}
2 changes: 1 addition & 1 deletion plugin/plugins/filesystem/nodes/keyfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (kd *KeyFS) Step(keyName string) (fsutils.WalkRef, error) {
opts := []nodeopts.AttachOption{
nodeopts.Parent(kd),
nodeopts.MFSPublish(ipnsPublisher(key.Name(), offlineAPI(kd.core).Name())),
nodeopts.MFSRoot(&cid),
nodeopts.MFSRoot(cid),
nodeopts.Logger(logging.Logger("IPNS-Key")),
}

Expand Down
14 changes: 12 additions & 2 deletions plugin/plugins/filesystem/nodes/mfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fsnodes

import (
"context"
"errors"
"fmt"
"io"
gopath "path"
Expand Down Expand Up @@ -44,6 +45,10 @@ type MFSFileMeta struct {
func MFSAttacher(ctx context.Context, core coreiface.CoreAPI, ops ...nodeopts.AttachOption) p9.Attacher {
options := nodeopts.AttachOps(ops...)

if !options.MFSRoot.Defined() {
panic("MFS root cid is required but was not defined in options")
}

mroot, err := cidToMFSRoot(ctx, options.MFSRoot, core, options.MFSPublish)
if err != nil {
panic(err)
Expand Down Expand Up @@ -385,10 +390,15 @@ func (md *MFS) ResolvedPath(names ...string) (corepath.Path, error) {
}
*/

func cidToMFSRoot(ctx context.Context, rootCid *cid.Cid, core coreiface.CoreAPI, publish mfs.PubFunc) (*mfs.Root, error) {
func cidToMFSRoot(ctx context.Context, rootCid cid.Cid, core coreiface.CoreAPI, publish mfs.PubFunc) (*mfs.Root, error) {

if !rootCid.Defined() {
return nil, errors.New("root cid was not defined")
}

callCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
ipldNode, err := core.Dag().Get(callCtx, *rootCid)
ipldNode, err := core.Dag().Get(callCtx, rootCid)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/plugins/filesystem/nodes/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type AttachOptions struct {
Parent fsutils.WalkRef // node directly behind self
Logger logging.EventLogger // what subsystem you are
Process goprocess.Process // TODO: I documented this somewhere else
MFSRoot *cid.Cid // required when attaching to MFS
MFSRoot cid.Cid // required when attaching to MFS
MFSPublish mfs.PubFunc
}

Expand Down Expand Up @@ -50,7 +50,7 @@ func Process(p goprocess.Process) AttachOption {
}
}

func MFSRoot(rcid *cid.Cid) AttachOption {
func MFSRoot(rcid cid.Cid) AttachOption {
return func(ops *AttachOptions) {
ops.MFSRoot = rcid
}
Expand Down

0 comments on commit 89735e3

Please sign in to comment.