Пример #1
0
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
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
}
Пример #3
0
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
}