コード例 #1
0
ファイル: add.go プロジェクト: Kubuxu/go-ipfs
func (adder *Adder) outputDirs(path string, fs mfs.FSNode) error {
	nd, err := fs.GetNode()
	if err != nil {
		return err
	}

	if !bytes.Equal(nd.Data, folderData) || fs.Type() != mfs.TDir {
		return nil
	}

	dir, ok := fs.(*mfs.Directory)
	if !ok {
		return fmt.Errorf("received FSNode of type TDir that was not a Directory")
	}

	for _, name := range dir.ListNames() {
		child, err := dir.Child(name)
		if err != nil {
			return err
		}

		err = adder.outputDirs(gopath.Join(path, name), child)
		if err != nil {
			return err
		}
	}

	return outputDagnode(adder.out, path, nd)
}
コード例 #2
0
ファイル: files.go プロジェクト: noffle/go-ipfs
func statNode(ds dag.DAGService, fsn mfs.FSNode) (*Object, error) {
	nd, err := fsn.GetNode()
	if err != nil {
		return nil, err
	}

	// add to dagserv to ensure its available
	k, err := ds.Add(nd)
	if err != nil {
		return nil, err
	}

	d, err := ft.FromBytes(nd.Data)
	if err != nil {
		return nil, err
	}

	cumulsize, err := nd.Size()
	if err != nil {
		return nil, err
	}

	return &Object{
		Hash:           k.B58String(),
		Blocks:         len(nd.Links),
		Size:           d.GetFilesize(),
		CumulativeSize: cumulsize,
	}, nil
}
コード例 #3
0
ファイル: add.go プロジェクト: qnib/go-ipfs
func (adder *Adder) outputDirs(path string, fsn mfs.FSNode) error {
	switch fsn := fsn.(type) {
	case *mfs.File:
		return nil
	case *mfs.Directory:
		for _, name := range fsn.ListNames() {
			child, err := fsn.Child(name)
			if err != nil {
				return err
			}

			childpath := gopath.Join(path, name)
			err = adder.outputDirs(childpath, child)
			if err != nil {
				return err
			}

			fsn.Uncache(name)
		}
		nd, err := fsn.GetNode()
		if err != nil {
			return err
		}

		return outputDagnode(adder.Out, path, nd)
	default:
		return fmt.Errorf("unrecognized fsn type: %#v", fsn)
	}
}
コード例 #4
0
ファイル: files.go プロジェクト: qnib/go-ipfs
func statNode(ds dag.DAGService, fsn mfs.FSNode) (*Object, error) {
	nd, err := fsn.GetNode()
	if err != nil {
		return nil, err
	}

	c := nd.Cid()

	pbnd, ok := nd.(*dag.ProtoNode)
	if !ok {
		return nil, dag.ErrNotProtobuf
	}

	d, err := ft.FromBytes(pbnd.Data())
	if err != nil {
		return nil, err
	}

	cumulsize, err := nd.Size()
	if err != nil {
		return nil, err
	}

	var ndtype string
	switch fsn.Type() {
	case mfs.TDir:
		ndtype = "directory"
	case mfs.TFile:
		ndtype = "file"
	default:
		return nil, fmt.Errorf("Unrecognized node type: %s", fsn.Type())
	}

	return &Object{
		Hash:           c.String(),
		Blocks:         len(nd.Links()),
		Size:           d.GetFilesize(),
		CumulativeSize: cumulsize,
		Type:           ndtype,
	}, nil
}
コード例 #5
0
ファイル: files.go プロジェクト: thomas-gardner/go-ipfs
func statNode(ds dag.DAGService, fsn mfs.FSNode) (*Object, error) {
	nd, err := fsn.GetNode()
	if err != nil {
		return nil, err
	}

	// add to dagserv to ensure its available
	k, err := ds.Add(nd)
	if err != nil {
		return nil, err
	}

	d, err := ft.FromBytes(nd.Data)
	if err != nil {
		return nil, err
	}

	cumulsize, err := nd.Size()
	if err != nil {
		return nil, err
	}

	var ndtype string
	switch fsn.Type() {
	case mfs.TDir:
		ndtype = "directory"
	case mfs.TFile:
		ndtype = "file"
	default:
		return nil, fmt.Errorf("unrecognized node type: %s", fsn.Type())
	}

	return &Object{
		Hash:           k.B58String(),
		Blocks:         len(nd.Links),
		Size:           d.GetFilesize(),
		CumulativeSize: cumulsize,
		Type:           ndtype,
	}, nil
}