Commit 8561017a authored by Mildred Ki'Lya's avatar Mildred Ki'Lya Committed by Shanti Bouchez-Mongardé

merkledag: Remove unused AddRecursive and RemoveRecursive

License: MIT
Signed-off-by: default avatarMildred Ki'Lya <mildred-pub.git@mildred.fr>
parent e02443c3
...@@ -18,10 +18,8 @@ var ErrNotFound = fmt.Errorf("merkledag: not found") ...@@ -18,10 +18,8 @@ var ErrNotFound = fmt.Errorf("merkledag: not found")
// DAGService is an IPFS Merkle DAG service. // DAGService is an IPFS Merkle DAG service.
type DAGService interface { type DAGService interface {
Add(*Node) (key.Key, error) Add(*Node) (key.Key, error)
AddRecursive(*Node) error
Get(context.Context, key.Key) (*Node, error) Get(context.Context, key.Key) (*Node, error)
Remove(*Node) error Remove(*Node) error
RemoveRecursive(*Node) error
// GetDAG returns, in order, all the single leve child // GetDAG returns, in order, all the single leve child
// nodes of the passed in node. // nodes of the passed in node.
...@@ -68,26 +66,6 @@ func (n *dagService) Batch() *Batch { ...@@ -68,26 +66,6 @@ func (n *dagService) Batch() *Batch {
return &Batch{ds: n, MaxSize: 8 * 1024 * 1024} return &Batch{ds: n, MaxSize: 8 * 1024 * 1024}
} }
// AddRecursive adds the given node and all child nodes to the BlockService
func (n *dagService) AddRecursive(nd *Node) error {
_, err := n.Add(nd)
if err != nil {
log.Info("AddRecursive Error: %s\n", err)
return err
}
for _, link := range nd.Links {
if link.node != nil {
err := n.AddRecursive(link.node)
if err != nil {
return err
}
}
}
return nil
}
// Get retrieves a node from the dagService, fetching the block in the BlockService // Get retrieves a node from the dagService, fetching the block in the BlockService
func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) { func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {
if n == nil { if n == nil {
...@@ -107,20 +85,6 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) { ...@@ -107,20 +85,6 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {
return DecodeProtobuf(b.Data) return DecodeProtobuf(b.Data)
} }
// Remove deletes the given node and all of its children from the BlockService
func (n *dagService) RemoveRecursive(nd *Node) error {
for _, l := range nd.Links {
if l.node != nil {
n.RemoveRecursive(l.node)
}
}
k, err := nd.Key()
if err != nil {
return err
}
return n.Blocks.DeleteBlock(k)
}
func (n *dagService) Remove(nd *Node) error { func (n *dagService) Remove(nd *Node) error {
k, err := nd.Key() k, err := nd.Key()
if err != nil { if err != nil {
......
...@@ -181,7 +181,7 @@ func runBatchFetchTest(t *testing.T, read io.Reader) { ...@@ -181,7 +181,7 @@ func runBatchFetchTest(t *testing.T, read io.Reader) {
t.Fatal(err) t.Fatal(err)
} }
err = dagservs[0].AddRecursive(root) _, err = dagservs[0].Add(root)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -232,45 +232,6 @@ func runBatchFetchTest(t *testing.T, read io.Reader) { ...@@ -232,45 +232,6 @@ func runBatchFetchTest(t *testing.T, read io.Reader) {
} }
} }
} }
func TestRecursiveAdd(t *testing.T) {
a := &Node{Data: []byte("A")}
b := &Node{Data: []byte("B")}
c := &Node{Data: []byte("C")}
d := &Node{Data: []byte("D")}
e := &Node{Data: []byte("E")}
err := a.AddNodeLink("blah", b)
if err != nil {
t.Fatal(err)
}
err = b.AddNodeLink("foo", c)
if err != nil {
t.Fatal(err)
}
err = b.AddNodeLink("bar", d)
if err != nil {
t.Fatal(err)
}
err = d.AddNodeLink("baz", e)
if err != nil {
t.Fatal(err)
}
dsp := getDagservAndPinner(t)
err = dsp.ds.AddRecursive(a)
if err != nil {
t.Fatal(err)
}
assertCanGet(t, dsp.ds, a)
assertCanGet(t, dsp.ds, b)
assertCanGet(t, dsp.ds, c)
assertCanGet(t, dsp.ds, d)
assertCanGet(t, dsp.ds, e)
}
func assertCanGet(t *testing.T, ds DAGService, n *Node) { func assertCanGet(t *testing.T, ds DAGService, n *Node) {
k, err := n.Key() k, err := n.Key()
......
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