Skip to content

Commit

Permalink
Fix to work correctly with RawNodes.
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed Oct 19, 2016
1 parent 092d5bf commit d5955ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 13 additions & 3 deletions core/coreunix/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestAddGCLive(t *testing.T) {
}
}

func TestAddWPosInfo(t *testing.T) {
func testAddWPosInfo(t *testing.T, rawLeaves bool) {
r := &repo.Mock{
C: config.Config{
Identity: config.Identity{
Expand All @@ -192,6 +192,7 @@ func TestAddWPosInfo(t *testing.T) {
}
adder.Out = make(chan interface{})
adder.Progress = true
adder.RawLeaves = rawLeaves

data := make([]byte, 5*1024*1024)
rand.New(rand.NewSource(2)).Read(data) // Rand.Read never returns an error
Expand All @@ -210,14 +211,23 @@ func TestAddWPosInfo(t *testing.T) {
}

if bs.countAtOffsetZero != 2 {
t.Fatal("expected 2 blocks with an offset at zero (one root, and one leaf), got %d", bs.countAtOffsetZero)
t.Fatal("expected 2 blocks with an offset at zero (one root and one leafh), got", bs.countAtOffsetZero)
}
if bs.countAtOffsetNonZero != 19 {
// note: the exact number will depend on the size and the sharding algo. used
t.Fatal("expected 19 blocks with an offset > 0, got %d", bs.countAtOffsetNonZero)
t.Fatal("expected 19 blocks with an offset > 0, got", bs.countAtOffsetNonZero)
}
}

func TestAddWPosInfo(t *testing.T) {
testAddWPosInfo(t, false)
}

func TestAddWPosInfoAndRawLeafs(t *testing.T) {
testAddWPosInfo(t, true)
}


type testBlockstore struct {
blockstore.GCBlockstore
expectedPath string
Expand Down
7 changes: 5 additions & 2 deletions importer/balanced/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func BalancedLayout(db *h.DagBuilderHelper) (node.Node, error) {

nroot := h.NewUnixfsNode()
db.SetPosInfo(nroot, 0)
println("SetPosInfo in root")

// add our old root as a child of the new root.
if root != nil { // nil if it's the first node.
Expand All @@ -28,7 +29,7 @@ func BalancedLayout(db *h.DagBuilderHelper) (node.Node, error) {
return nil, err
}

offset = nroot.FileSize()
offset = nroot.DataSize()
root = nroot

}
Expand Down Expand Up @@ -74,6 +75,8 @@ func fillNodeRec(db *h.DagBuilderHelper, node *h.UnixfsNode, depth int, offset u
for node.NumChildren() < db.Maxlinks() && !db.Done() {
child := h.NewUnixfsNode()
db.SetPosInfo(child, offset)
println("SetPosInfo in loop")
println(offset)

err := fillNodeRec(db, child, depth-1, offset)
if err != nil {
Expand All @@ -83,7 +86,7 @@ func fillNodeRec(db *h.DagBuilderHelper, node *h.UnixfsNode, depth int, offset u
if err := node.AddChild(child, db); err != nil {
return err
}
offset += child.FileSize()
offset += child.DataSize()
}

return nil
Expand Down

0 comments on commit d5955ce

Please sign in to comment.