예제 #1
0
파일: add.go 프로젝트: djbarber/ipfs-hack
// Add the given file while respecting the params.
func (params *adder) addFile(file files.File) (*dag.Node, error) {
	// Check if file is hidden
	if fileIsHidden := files.IsHidden(file); fileIsHidden && !params.hidden {
		log.Debugf("%s is hidden, skipping", file.FileName())
		return nil, &hiddenFileError{file.FileName()}
	}

	// Check if "file" is actually a directory
	if file.IsDirectory() {
		return params.addDir(file)
	}

	if s, ok := file.(*files.Symlink); ok {
		sdata, err := ft.SymlinkData(s.Target)
		if err != nil {
			return nil, err
		}

		dagnode := &dag.Node{Data: sdata}
		_, err = params.node.DAG.Add(dagnode)
		if err != nil {
			return nil, err
		}

		err = params.addNode(dagnode, s.FileName())
		return dagnode, err
	}

	// if the progress flag was specified, wrap the file so that we can send
	// progress updates to the client (over the output channel)
	var reader io.Reader = file
	if params.progress {
		reader = &progressReader{file: file, out: params.out}
	}

	dagnode, err := add(params.node, reader, params.trickle, params.chunker)
	if err != nil {
		return nil, err
	}

	// patch it into the root
	log.Infof("adding file: %s", file.FileName())
	err = params.addNode(dagnode, file.FileName())
	return dagnode, err
}
예제 #2
0
파일: add.go 프로젝트: djbarber/ipfs-hack
func addFile(n *core.IpfsNode, file files.File) (*merkledag.Node, error) {
	if file.IsDirectory() {
		return addDir(n, file)
	}
	return add(n, file)
}