1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-17 16:37:59 +08:00

implement 'editor' abstraction

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2015-07-28 14:12:01 -07:00
parent 314f7bbfea
commit b32d0ef153
4 changed files with 140 additions and 68 deletions

View File

@ -587,13 +587,17 @@ func rmLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
return "", err
}
path := strings.Split(req.Arguments()[2], "/")
path := req.Arguments()[2]
nnode, err := dagutils.RmLink(req.Context(), nd.DAG, root, path)
e := dagutils.NewDagEditor(nd.DAG, root)
err = e.RmLink(req.Context(), path)
if err != nil {
return "", err
}
nnode := e.GetNode()
return nnode.Key()
}
@ -610,17 +614,27 @@ func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
path := req.Arguments()[2]
childk := key.B58KeyDecode(req.Arguments()[3])
parts := strings.Split(path, "/")
create, _, err := req.Option("create").Bool()
if err != nil {
return "", err
}
nnode, err := dagutils.InsertNodeAtPath(req.Context(), nd.DAG, root, parts, childk, create)
var createfunc func() *dag.Node
if create {
createfunc = func() *dag.Node {
return &dag.Node{Data: ft.FolderPBData()}
}
}
e := dagutils.NewDagEditor(nd.DAG, root)
err = e.InsertNodeAtPath(req.Context(), path, childk, createfunc)
if err != nil {
return "", err
}
nnode := e.GetNode()
return nnode.Key()
}