Commit ae63887c authored by Jeromy's avatar Jeromy Committed by Juan Batiz-Benet

add-only-hash no longer stores entirety of everything in memory

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent b7715c8a
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context" context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
key "github.com/ipfs/go-ipfs/blocks/key"
dag "github.com/ipfs/go-ipfs/merkledag" dag "github.com/ipfs/go-ipfs/merkledag"
) )
...@@ -26,21 +25,17 @@ func (e *Editor) GetNode() *dag.Node { ...@@ -26,21 +25,17 @@ func (e *Editor) GetNode() *dag.Node {
return e.root.Copy() return e.root.Copy()
} }
func (e *Editor) AddLink(ctx context.Context, childname string, childk key.Key) error { func (e *Editor) GetDagService() dag.DAGService {
nd, err := addLink(ctx, e.ds, e.root, childname, childk) return e.ds
if err != nil {
return err
}
e.root = nd
return nil
} }
func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname string, childk key.Key) (*dag.Node, error) { func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname string, childnd *dag.Node) (*dag.Node, error) {
if childname == "" { if childname == "" {
return nil, errors.New("cannot create link with no name!") return nil, errors.New("cannot create link with no name!")
} }
childnd, err := ds.Get(ctx, childk) // ensure that the node we are adding is in the dagservice
_, err := ds.Add(childnd)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -58,7 +53,7 @@ func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname s ...@@ -58,7 +53,7 @@ func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname s
return root, nil return root, nil
} }
func (e *Editor) InsertNodeAtPath(ctx context.Context, path string, toinsert key.Key, create func() *dag.Node) error { func (e *Editor) InsertNodeAtPath(ctx context.Context, path string, toinsert *dag.Node, create func() *dag.Node) error {
splpath := strings.Split(path, "/") splpath := strings.Split(path, "/")
nd, err := insertNodeAtPath(ctx, e.ds, e.root, splpath, toinsert, create) nd, err := insertNodeAtPath(ctx, e.ds, e.root, splpath, toinsert, create)
if err != nil { if err != nil {
...@@ -68,7 +63,7 @@ func (e *Editor) InsertNodeAtPath(ctx context.Context, path string, toinsert key ...@@ -68,7 +63,7 @@ func (e *Editor) InsertNodeAtPath(ctx context.Context, path string, toinsert key
return nil return nil
} }
func insertNodeAtPath(ctx context.Context, ds dag.DAGService, root *dag.Node, path []string, toinsert key.Key, create func() *dag.Node) (*dag.Node, error) { func insertNodeAtPath(ctx context.Context, ds dag.DAGService, root *dag.Node, path []string, toinsert *dag.Node, create func() *dag.Node) (*dag.Node, error) {
if len(path) == 1 { if len(path) == 1 {
return addLink(ctx, ds, root, path[0], toinsert) return addLink(ctx, ds, root, path[0], toinsert)
} }
......
...@@ -23,7 +23,7 @@ func TestAddLink(t *testing.T) { ...@@ -23,7 +23,7 @@ func TestAddLink(t *testing.T) {
} }
nd := new(dag.Node) nd := new(dag.Node)
nnode, err := addLink(context.Background(), ds, nd, "fish", fk) nnode, err := addLink(context.Background(), ds, nd, "fish", fishnode)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -104,7 +104,7 @@ func testInsert(t *testing.T, e *Editor, path, data string, create bool, experr ...@@ -104,7 +104,7 @@ func testInsert(t *testing.T, e *Editor, path, data string, create bool, experr
} }
} }
err = e.InsertNodeAtPath(context.Background(), path, ck, c) err = e.InsertNodeAtPath(context.Background(), path, child, c)
if experr != "" { if experr != "" {
var got string var got string
if err != nil { if err != nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment