Skip to content

Commit

Permalink
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 Feb 12, 2017
1 parent c179b4d commit 10e2401
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 4 additions & 0 deletions filestore/fsrefstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ func (f *FileManager) getDataObj(c *cid.Cid) (*pb.DataObj, error) {
//
}

return unmarshalDataObj(o)
}

func unmarshalDataObj(o interface{}) (*pb.DataObj, error) {
data, ok := o.([]byte)
if !ok {
return nil, fmt.Errorf("stored filestore dataobj was not a []byte")
Expand Down
12 changes: 3 additions & 9 deletions filestore/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
dsq "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore/query"
proto "gx/ipfs/QmT6n4mspWYEya864BhCUJEgyxiRfmiSY9ruQwTUNpRKaM/protobuf/proto"
cid "gx/ipfs/QmcTcsTvfaeEBRFo1TkFgT8sRmgi1n1LTZpecfVP8fzpGD/go-cid"
)

Expand Down Expand Up @@ -124,17 +123,12 @@ func next(qr dsq.Results) (*cid.Cid, *pb.DataObj, error) {
return nil, nil, fmt.Errorf("decoding cid from filestore: %s", err)
}

data, ok := v.Value.([]byte)
if !ok {
return c, nil, fmt.Errorf("stored filestore dataobj was not a []byte")
}

var dobj pb.DataObj
if err := proto.Unmarshal(data, &dobj); err != nil {
dobj, err := unmarshalDataObj(v.Value)
if err != nil {
return c, nil, err
}

return c, &dobj, nil
return c, dobj, nil
}

func mkListRes(c *cid.Cid, d *pb.DataObj, err error) *ListRes {
Expand Down

0 comments on commit 10e2401

Please sign in to comment.