Skip to content

Commit

Permalink
Filestore: Minor Refactor.
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 Jun 1, 2016
1 parent 757cb35 commit cce39eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion filestore/util/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (p *params) convertToFile(key bk.Key, root bool, offset uint64) (uint64, er
return 0, err
}
dataObj.Flags |= NoBlockData
pbnode := n.GetPBNode(true)
pbnode := n.GetPBNode()
pbnode.Data, err = fsnode.GetBytesNoData()
if err != nil {
return 0, err
Expand Down
22 changes: 9 additions & 13 deletions merkledag/coding.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (n *Node) unmarshal(encoded []byte) error {
// Marshal encodes a *Node instance into a new byte slice.
// The conversion uses an intermediate PBNode.
func (n *Node) Marshal() ([]byte, error) {
pbn := n.GetPBNode(true)
pbn := n.GetPBNode()
data, err := pbn.Marshal()
if err != nil {
return data, fmt.Errorf("Marshal failed. %v", err)
Expand All @@ -49,15 +49,18 @@ func (n *Node) Marshal() ([]byte, error) {
}

func (n *Node) MarshalNoData() ([]byte, error) {
pbn := n.GetPBNode(false)
pbn := n.GetPBNode()
if n.DataPtr != nil && len(n.DataPtr.AltData) > 0 {
pbn.Data = n.DataPtr.AltData
}
data, err := pbn.Marshal()
if err != nil {
return data, fmt.Errorf("Marshal failed. %v", err)
}
return data, nil
}

func (n *Node) GetPBNode(useData bool) *pb.PBNode {
func (n *Node) GetPBNode() *pb.PBNode {
pbn := &pb.PBNode{}
if len(n.Links) > 0 {
pbn.Links = make([]*pb.PBLink, len(n.Links))
Expand All @@ -71,17 +74,10 @@ func (n *Node) GetPBNode(useData bool) *pb.PBNode {
pbn.Links[i].Hash = []byte(l.Hash)
}

if useData {
if len(n.Data) > 0 {
pbn.Data = n.Data
}
} else {
if n.DataPtr != nil && len(n.DataPtr.AltData) > 0 {
pbn.Data = n.DataPtr.AltData
} else if len(n.Data) > 0 {
pbn.Data = n.Data
}
if len(n.Data) > 0 {
pbn.Data = n.Data
}

return pbn
}

Expand Down

0 comments on commit cce39eb

Please sign in to comment.