func addDir(n *core.IpfsNode, dir files.File) (*merkledag.Node, error) { tree := &merkledag.Node{Data: unixfs.FolderPBData()} Loop: for { file, err := dir.NextFile() switch { case err != nil && err != io.EOF: return nil, err case err == io.EOF: break Loop } node, err := addFile(n, file) if err != nil { return nil, err } _, name := gopath.Split(file.FileName()) if err := tree.AddNodeLink(name, node); err != nil { return nil, err } } if err := addNode(n, tree); err != nil { return nil, err } return tree, nil }
func (params *adder) addDir(file files.File) (*dag.Node, error) { tree := &dag.Node{Data: ft.FolderPBData()} log.Infof("adding directory: %s", file.FileName()) for { file, err := file.NextFile() if err != nil && err != io.EOF { return nil, err } if file == nil { break } node, err := params.addFile(file) if _, ok := err.(*hiddenFileError); ok { // hidden file error, set the node to nil for below node = nil } else if err != nil { return nil, err } if node != nil { _, name := path.Split(file.FileName()) err = tree.AddNodeLink(name, node) if err != nil { return nil, err } } } if err := params.addNode(tree, file.FileName()); err != nil { return nil, err } k, err := params.node.DAG.Add(tree) if err != nil { return nil, err } params.node.Pinning.GetManual().PinWithMode(k, pin.Indirect) return tree, nil }