Skip to content

Commit

Permalink
merkeldag: change SetPrefix param to a pointer and reset the prefix o…
Browse files Browse the repository at this point in the history
…n nil

License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed Mar 27, 2017
1 parent 92cc46e commit 5adb2a3
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ You can now refer to the added file in a gateway, like so:
fileAdder.Silent = silent
fileAdder.RawLeaves = rawblks
fileAdder.NoCopy = nocopy
fileAdder.Prefix = prefix
fileAdder.Prefix = &prefix

if hash {
md := dagtest.Mock()
Expand Down
3 changes: 2 additions & 1 deletion core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type Adder struct {
mroot *mfs.Root
unlocker bs.Unlocker
tempRoot *cid.Cid
Prefix cid.Prefix
Prefix *cid.Prefix
}

func (adder *Adder) mfsRoot() (*mfs.Root, error) {
Expand All @@ -113,6 +113,7 @@ func (adder *Adder) mfsRoot() (*mfs.Root, error) {
rnode := unixfs.EmptyDirNode()
rnode.SetPrefix(adder.Prefix)
mr, err := mfs.NewRoot(adder.ctx, adder.dagService, rnode, nil)
mr.Prefix = adder.Prefix
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions importer/helpers/dagbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type DagBuilderHelper struct {
batch *dag.Batch
fullPath string
stat os.FileInfo
prefix cid.Prefix
prefix *cid.Prefix
}

type DagBuilderParams struct {
Expand All @@ -36,8 +36,8 @@ type DagBuilderParams struct {
// instead of using the unixfs TRaw type
RawLeaves bool

// CID Prefix to use
Prefix cid.Prefix
// CID Prefix to use if set
Prefix *cid.Prefix

// DAGService to write blocks to (required)
Dagserv dag.DAGService
Expand Down
2 changes: 1 addition & 1 deletion importer/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewUnixfsNodeFromDag(nd *dag.ProtoNode) (*UnixfsNode, error) {
}, nil
}

func (n *UnixfsNode) SetPrefix(prefix cid.Prefix) {
func (n *UnixfsNode) SetPrefix(prefix *cid.Prefix) {
n.node.SetPrefix(prefix)
}

Expand Down
17 changes: 12 additions & 5 deletions merkledag/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ func PrefixForCidVersion(version int) (cid.Prefix, error) {
}
}

func (n *ProtoNode) SetPrefix(prefix cid.Prefix) {
n.Prefix = prefix
n.encoded = nil
n.cached = nil
// SetPrefix sets the prefix if it is non nil, if prefix is nil then
// it resets it the default value
func (n *ProtoNode) SetPrefix(prefix *cid.Prefix) {
if prefix == nil {
n.Prefix = v0CidPrefix
} else {
n.Prefix = *prefix
n.Prefix.Codec = cid.DagProtobuf
n.encoded = nil
n.cached = nil
}
}

type LinkSlice []*node.Link
Expand Down Expand Up @@ -287,7 +294,7 @@ func (n *ProtoNode) Cid() *cid.Cid {
}

if n.Prefix.Codec == 0 {
n.Prefix = v0CidPrefix
n.SetPrefix(nil)
}

c, err := n.Prefix.Sum(n.RawData())
Expand Down
2 changes: 1 addition & 1 deletion mfs/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewDirectory(ctx context.Context, name string, node node.Node, parent child
}, nil
}

func (d *Directory) SetPrefix(prefix cid.Prefix) {
func (d *Directory) SetPrefix(prefix *cid.Prefix) {
d.dirbuilder.SetPrefix(prefix)
}

Expand Down
2 changes: 1 addition & 1 deletion mfs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Root struct {
Type string

// Prefix to use for any children created
Prefix cid.Prefix
Prefix *cid.Prefix
}

type PubFunc func(context.Context, *cid.Cid) error
Expand Down
2 changes: 1 addition & 1 deletion unixfs/io/dirbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func NewDirectoryFromNode(dserv mdag.DAGService, nd node.Node) (*Directory, erro
}

// SetPrefix sets the prefix of the root node
func (d *Directory) SetPrefix(prefix cid.Prefix) {
func (d *Directory) SetPrefix(prefix *cid.Prefix) {
if d.dirnode != nil {
d.dirnode.SetPrefix(prefix)
}
Expand Down

0 comments on commit 5adb2a3

Please sign in to comment.