Ejemplo n.º 1
0
Archivo: object.go Proyecto: rht/ipget
func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
	if len(req.Arguments()) < 4 {
		return "", fmt.Errorf("not enough arguments for add-link")
	}

	nd, err := req.InvocContext().GetNode()
	if err != nil {
		return "", err
	}

	path := req.Arguments()[2]
	childk := key.B58KeyDecode(req.Arguments()[3])

	create, _, err := req.Option("create").Bool()
	if err != nil {
		return "", err
	}

	var createfunc func() *dag.Node
	if create {
		createfunc = func() *dag.Node {
			return &dag.Node{Data: ft.FolderPBData()}
		}
	}

	e := dagutils.NewDagEditor(nd.DAG, root)

	childnd, err := nd.DAG.Get(req.Context(), childk)
	if err != nil {
		return "", err
	}

	err = e.InsertNodeAtPath(req.Context(), path, childnd, createfunc)
	if err != nil {
		return "", err
	}

	nnode := e.GetNode()

	return nnode.Key()
}
Ejemplo n.º 2
0
Archivo: object.go Proyecto: rht/ipget
func rmLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
	if len(req.Arguments()) < 3 {
		return "", fmt.Errorf("not enough arguments for rm-link")
	}

	nd, err := req.InvocContext().GetNode()
	if err != nil {
		return "", err
	}

	path := req.Arguments()[2]

	e := dagutils.NewDagEditor(nd.DAG, root)

	err = e.RmLink(req.Context(), path)
	if err != nil {
		return "", err
	}

	nnode := e.GetNode()

	return nnode.Key()
}
Ejemplo n.º 3
0
Archivo: add.go Proyecto: rht/ipget
	},
	Run: func(req cmds.Request, res cmds.Response) {
		n, err := req.InvocContext().GetNode()
		if err != nil {
			res.SetError(err, cmds.ErrNormal)
			return
		}

		progress, _, _ := req.Option(progressOptionName).Bool()
		trickle, _, _ := req.Option(trickleOptionName).Bool()
		wrap, _, _ := req.Option(wrapOptionName).Bool()
		hash, _, _ := req.Option(onlyHashOptionName).Bool()
		hidden, _, _ := req.Option(hiddenOptionName).Bool()
		chunker, _, _ := req.Option(chunkerOptionName).String()

		e := dagutils.NewDagEditor(NewMemoryDagService(), newDirNode())
		if hash {
			nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{
				//TODO: need this to be true or all files
				// hashed will be stored in memory!
				NilRepo: true,
			})
			if err != nil {
				res.SetError(err, cmds.ErrNormal)
				return
			}
			n = nilnode
		}

		outChan := make(chan interface{}, 8)
		res.SetOutput((<-chan interface{})(outChan))