func (rw *RefWriter) writeRefsRecursive(n node.Node) (int, error) { nc := n.Cid() var count int for i, ng := range dag.GetDAG(rw.Ctx, rw.DAG, n) { lc := n.Links()[i].Cid if rw.skip(lc) { continue } if err := rw.WriteEdge(nc, lc, n.Links()[i].Name); err != nil { return count, err } nd, err := ng.Get(rw.Ctx) if err != nil { return count, err } c, err := rw.writeRefsRecursive(nd) count += c if err != nil { return count, err } } return count, nil }
// GetDAG will fill out all of the links of the given Node. // It returns a channel of nodes, which the caller can receive // all the child nodes of 'root' on, in proper order. func GetDAG(ctx context.Context, ds DAGService, root node.Node) []NodeGetter { var cids []*cid.Cid for _, lnk := range root.Links() { cids = append(cids, lnk.Cid) } return GetNodes(ctx, ds, cids) }
func getOutput(dagnode node.Node) (*Object, error) { c := dagnode.Cid() output := &Object{ Hash: c.String(), Links: make([]Link, len(dagnode.Links())), } for i, link := range dagnode.Links() { output.Links[i] = Link{ Name: link.Name, Hash: link.Cid.String(), Size: link.Size, } } return output, nil }
func (rw *RefWriter) writeRefsSingle(n node.Node) (int, error) { c := n.Cid() if rw.skip(c) { return 0, nil } count := 0 for _, l := range n.Links() { lc := l.Cid if rw.skip(lc) { continue } if err := rw.WriteEdge(c, lc, l.Name); err != nil { return count, err } count++ } return count, nil }
// NewDagReader creates a new reader object that reads the data represented by // the given node, using the passed in DAGService for data retreival func NewDagReader(ctx context.Context, n node.Node, serv mdag.DAGService) (DagReader, error) { switch n := n.(type) { case *mdag.RawNode: return NewBufDagReader(n.RawData()), nil case *mdag.ProtoNode: pb := new(ftpb.Data) if err := proto.Unmarshal(n.Data(), pb); err != nil { return nil, err } switch pb.GetType() { case ftpb.Data_Directory: // Dont allow reading directories return nil, ErrIsDir case ftpb.Data_File, ftpb.Data_Raw: return NewPBFileReader(ctx, n, pb, serv), nil case ftpb.Data_Metadata: if len(n.Links()) == 0 { return nil, errors.New("incorrectly formatted metadata object") } child, err := n.Links()[0].GetNode(ctx, serv) if err != nil { return nil, err } childpb, ok := child.(*mdag.ProtoNode) if !ok { return nil, mdag.ErrNotProtobuf } return NewDagReader(ctx, childpb, serv) case ftpb.Data_Symlink: return nil, ErrCantReadSymlinks default: return nil, ft.ErrUnrecognizedType } default: return nil, fmt.Errorf("unrecognized node type") } }