Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #56 from ipfs/fix/nocopy-errors
Browse files Browse the repository at this point in the history
Unixfs: enforce refs on files when using nocopy
  • Loading branch information
Stebalien authored Jan 23, 2019
2 parents 63cc1b6 + 4fcb63f commit 3d211e5
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.12: QmQXze9tG878pa4Euya4rrDpyTNX3kQe4dhCaBzBozGgpe
1.2.13: QmQReF8uaPBw6uKbDZQzaWyxCL4NuMMotcztXv1fKTSzkg
7 changes: 6 additions & 1 deletion importer/balanced/balanced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ func buildTestDag(ds ipld.DAGService, spl chunker.Splitter) (*dag.ProtoNode, err
Maxlinks: h.DefaultLinksPerBlock,
}

nd, err := Layout(dbp.New(spl))
db, err := dbp.New(spl)
if err != nil {
return nil, err
}

nd, err := Layout(db)
if err != nil {
return nil, err
}
Expand Down
12 changes: 10 additions & 2 deletions importer/helpers/dagbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helpers

import (
"context"
"errors"
"io"
"os"

Expand All @@ -17,6 +18,8 @@ import (
ipld "github.com/ipfs/go-ipld-format"
)

var ErrMissingFsRef = errors.New("missing file path or URL, can't create filestore reference")

// DagBuilderHelper wraps together a bunch of objects needed to
// efficiently create unixfs dag trees
type DagBuilderHelper struct {
Expand Down Expand Up @@ -71,7 +74,7 @@ type DagBuilderParams struct {

// New generates a new DagBuilderHelper from the given params and a given
// chunker.Splitter as data source.
func (dbp *DagBuilderParams) New(spl chunker.Splitter) *DagBuilderHelper {
func (dbp *DagBuilderParams) New(spl chunker.Splitter) (*DagBuilderHelper, error) {
db := &DagBuilderHelper{
dserv: dbp.Dagserv,
spl: spl,
Expand All @@ -87,7 +90,12 @@ func (dbp *DagBuilderParams) New(spl chunker.Splitter) *DagBuilderHelper {
if dbp.URL != "" && dbp.NoCopy {
db.fullPath = dbp.URL
}
return db

if dbp.NoCopy && db.fullPath == "" { // Enforce NoCopy
return nil, ErrMissingFsRef
}

return db, nil
}

// prepareNext consumes the next item from the splitter and puts it
Expand Down
13 changes: 10 additions & 3 deletions importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ func BuildDagFromReader(ds ipld.DAGService, spl chunker.Splitter) (ipld.Node, er
Dagserv: ds,
Maxlinks: h.DefaultLinksPerBlock,
}

return bal.Layout(dbp.New(spl))
db, err := dbp.New(spl)
if err != nil {
return nil, err
}
return bal.Layout(db)
}

// BuildTrickleDagFromReader creates a DAG given a DAGService and a Splitter
Expand All @@ -30,5 +33,9 @@ func BuildTrickleDagFromReader(ds ipld.DAGService, spl chunker.Splitter) (ipld.N
Maxlinks: h.DefaultLinksPerBlock,
}

return trickle.Layout(dbp.New(spl))
db, err := dbp.New(spl)
if err != nil {
return nil, err
}
return trickle.Layout(db)
}
37 changes: 32 additions & 5 deletions importer/trickle/trickle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ func buildTestDag(ds ipld.DAGService, spl chunker.Splitter, rawLeaves UseRawLeav
RawLeaves: bool(rawLeaves),
}

nd, err := Layout(dbp.New(spl))
db, err := dbp.New(spl)
if err != nil {
return nil, err
}

nd, err := Layout(db)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -503,7 +508,13 @@ func testAppend(t *testing.T, rawLeaves UseRawLeaves) {
r := bytes.NewReader(should[nbytes/2:])

ctx := context.Background()
nnode, err := Append(ctx, nd, dbp.New(chunker.NewSizeSplitter(r, 500)))

db, err := dbp.New(chunker.NewSizeSplitter(r, 500))
if err != nil {
t.Fatal(err)
}

nnode, err := Append(ctx, nd, db)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -564,7 +575,12 @@ func testMultipleAppends(t *testing.T, rawLeaves UseRawLeaves) {
ctx := context.Background()
for i := 0; i < len(should); i++ {

nnode, err := Append(ctx, nd, dbp.New(spl(bytes.NewReader(should[i:i+1]))))
db, err := dbp.New(spl(bytes.NewReader(should[i : i+1])))
if err != nil {
t.Fatal(err)
}

nnode, err := Append(ctx, nd, db)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -612,12 +628,23 @@ func TestAppendSingleBytesToEmpty(t *testing.T) {
spl := chunker.SizeSplitterGen(500)

ctx := context.Background()
nnode, err := Append(ctx, nd, dbp.New(spl(bytes.NewReader(data[:1]))))

db, err := dbp.New(spl(bytes.NewReader(data[:1])))
if err != nil {
t.Fatal(err)
}

nnode, err := Append(ctx, nd, db)
if err != nil {
t.Fatal(err)
}

db, err = dbp.New(spl(bytes.NewReader(data[1:])))
if err != nil {
t.Fatal(err)
}

nnode, err = Append(ctx, nnode, dbp.New(spl(bytes.NewReader(data[1:]))))
nnode, err = Append(ctx, nnode, db)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 5 additions & 1 deletion mod/dagmodifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ func (dm *DagModifier) appendData(nd ipld.Node, spl chunker.Splitter) (ipld.Node
CidBuilder: dm.Prefix,
RawLeaves: dm.RawLeaves,
}
return trickle.Append(dm.ctx, nd, dbp.New(spl))
db, err := dbp.New(spl)
if err != nil {
return nil, err
}
return trickle.Append(dm.ctx, nd, db)
default:
return nil, ErrNotUnixfs
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@
"license": "",
"name": "go-unixfs",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.2.12"
"version": "1.2.13"
}

6 changes: 5 additions & 1 deletion test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ func GetNode(t testing.TB, dserv ipld.DAGService, data []byte, opts NodeOpts) ip
RawLeaves: opts.RawLeavesUsed,
}

node, err := trickle.Layout(dbp.New(SizeSplitterGen(500)(in)))
db, err := dbp.New(SizeSplitterGen(500)(in))
if err != nil {
t.Fatal(err)
}
node, err := trickle.Layout(db)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 3d211e5

Please sign in to comment.