示例#1
0
func appendFile(args []files.File, inputs []string, argDef *cmds.Argument, recursive bool) ([]files.File, []string, error) {
	fpath := inputs[0]

	if fpath == "." {
		cwd, err := os.Getwd()
		if err != nil {
			return nil, nil, err
		}
		fpath = cwd
	}
	stat, err := os.Lstat(fpath)
	if err != nil {
		return nil, nil, err
	}

	if stat.IsDir() {
		if !argDef.Recursive {
			err = fmt.Errorf("Invalid path '%s', argument '%s' does not support directories",
				fpath, argDef.Name)
			return nil, nil, err
		}
		if !recursive {
			err = fmt.Errorf("'%s' is a directory, use the '-%s' flag to specify directories",
				fpath, cmds.RecShort)
			return nil, nil, err
		}
	}

	arg, err := files.NewSerialFile(path.Base(fpath), fpath, stat)
	if err != nil {
		return nil, nil, err
	}
	return append(args, arg), inputs[1:], nil
}
示例#2
0
文件: add.go 项目: djbarber/ipfs-hack
// AddR recursively adds files in |path|.
func AddR(n *core.IpfsNode, root string) (key string, err error) {
	stat, err := os.Lstat(root)
	if err != nil {
		return "", err
	}

	f, err := files.NewSerialFile(root, root, stat)
	if err != nil {
		return "", err
	}
	defer f.Close()

	dagnode, err := addFile(n, f)
	if err != nil {
		return "", err
	}

	k, err := dagnode.Key()
	if err != nil {
		return "", err
	}

	n.Pinning.GetManual().RemovePinWithMode(k, pin.Indirect)
	if err := n.Pinning.Flush(); err != nil {
		return "", err
	}

	return k.String(), nil
}
示例#3
0
// Builds a DAG from the given file, writing created blocks to disk as they are
// created
func BuildDagFromFile(fpath string, ds dag.DAGService, mp pin.ManualPinner) (*dag.Node, error) {
	stat, err := os.Lstat(fpath)
	if err != nil {
		return nil, err
	}

	if stat.IsDir() {
		return nil, fmt.Errorf("`%s` is a directory", fpath)
	}

	f, err := files.NewSerialFile(fpath, fpath, stat)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	return BuildDagFromReader(ds, chunk.NewSizeSplitter(f, chunk.DefaultBlockSize), BasicPinnerCB(mp))
}