Commit 96269e02 authored by Kevin Atkinson's avatar Kevin Atkinson

filestore: Refactor.

License: MIT
Signed-off-by: default avatarKevin Atkinson <k@kevina.org>
parent 81af0347
......@@ -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")
......
......@@ -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/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
)
......@@ -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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment