Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-merkledag
Commits
ae63887c
Commit
ae63887c
authored
Aug 14, 2015
by
Jeromy
Committed by
Juan Batiz-Benet
Sep 05, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add-only-hash no longer stores entirety of everything in memory
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
b7715c8a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
14 deletions
+9
-14
utils/utils.go
utils/utils.go
+7
-12
utils/utils_test.go
utils/utils_test.go
+2
-2
No files found.
utils/utils.go
View file @
ae63887c
...
...
@@ -6,7 +6,6 @@ import (
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"
)
...
...
@@ -26,21 +25,17 @@ func (e *Editor) GetNode() *dag.Node {
return
e
.
root
.
Copy
()
}
func
(
e
*
Editor
)
AddLink
(
ctx
context
.
Context
,
childname
string
,
childk
key
.
Key
)
error
{
nd
,
err
:=
addLink
(
ctx
,
e
.
ds
,
e
.
root
,
childname
,
childk
)
if
err
!=
nil
{
return
err
}
e
.
root
=
nd
return
nil
func
(
e
*
Editor
)
GetDagService
()
dag
.
DAGService
{
return
e
.
ds
}
func
addLink
(
ctx
context
.
Context
,
ds
dag
.
DAGService
,
root
*
dag
.
Node
,
childname
string
,
child
k
key
.
Key
)
(
*
dag
.
Node
,
error
)
{
func
addLink
(
ctx
context
.
Context
,
ds
dag
.
DAGService
,
root
*
dag
.
Node
,
childname
string
,
child
nd
*
dag
.
Node
)
(
*
dag
.
Node
,
error
)
{
if
childname
==
""
{
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
{
return
nil
,
err
}
...
...
@@ -58,7 +53,7 @@ func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname s
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
,
"/"
)
nd
,
err
:=
insertNodeAtPath
(
ctx
,
e
.
ds
,
e
.
root
,
splpath
,
toinsert
,
create
)
if
err
!=
nil
{
...
...
@@ -68,7 +63,7 @@ func (e *Editor) InsertNodeAtPath(ctx context.Context, path string, toinsert key
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
{
return
addLink
(
ctx
,
ds
,
root
,
path
[
0
],
toinsert
)
}
...
...
utils/utils_test.go
View file @
ae63887c
...
...
@@ -23,7 +23,7 @@ func TestAddLink(t *testing.T) {
}
nd
:=
new
(
dag
.
Node
)
nnode
,
err
:=
addLink
(
context
.
Background
(),
ds
,
nd
,
"fish"
,
f
k
)
nnode
,
err
:=
addLink
(
context
.
Background
(),
ds
,
nd
,
"fish"
,
f
ishnode
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -104,7 +104,7 @@ func testInsert(t *testing.T, e *Editor, path, data string, create bool, experr
}
}
err
=
e
.
InsertNodeAtPath
(
context
.
Background
(),
path
,
c
k
,
c
)
err
=
e
.
InsertNodeAtPath
(
context
.
Background
(),
path
,
c
hild
,
c
)
if
experr
!=
""
{
var
got
string
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment