From d5955cee089f59ed7a5ffcfda780cb0a365ef52e Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Tue, 18 Oct 2016 21:52:28 -0400 Subject: [PATCH] Fix to work correctly with RawNodes. License: MIT Signed-off-by: Kevin Atkinson --- core/coreunix/add_test.go | 16 +++++++++++++--- importer/balanced/builder.go | 7 +++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/core/coreunix/add_test.go b/core/coreunix/add_test.go index af36281fdcc9..fbfab82ea772 100644 --- a/core/coreunix/add_test.go +++ b/core/coreunix/add_test.go @@ -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{ @@ -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 @@ -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 diff --git a/importer/balanced/builder.go b/importer/balanced/builder.go index 057126c1c3db..f5af5b359042 100644 --- a/importer/balanced/builder.go +++ b/importer/balanced/builder.go @@ -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. @@ -28,7 +29,7 @@ func BalancedLayout(db *h.DagBuilderHelper) (node.Node, error) { return nil, err } - offset = nroot.FileSize() + offset = nroot.DataSize() root = nroot } @@ -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 { @@ -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