mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-02 03:28:25 +08:00
add partial resolving to resolver code
License: MIT Signed-off-by: Jeromy <why@ipfs.io>
This commit is contained in:
@ -137,13 +137,23 @@ var DagGetCmd = &cmds.Command{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err := n.Resolver.ResolvePath(req.Context(), p)
|
obj, rem, err := n.Resolver.ResolveToLastNode(req.Context(), p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmds.ErrNormal)
|
res.SetError(err, cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res.SetOutput(obj)
|
var out interface{} = obj
|
||||||
|
if len(rem) > 0 {
|
||||||
|
final, _, err := obj.Resolve(rem)
|
||||||
|
if err != nil {
|
||||||
|
res.SetError(err, cmds.ErrNormal)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
out = final
|
||||||
|
}
|
||||||
|
|
||||||
|
res.SetOutput(out)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,39 @@ func SplitAbsPath(fpath Path) (*cid.Cid, []string, error) {
|
|||||||
return c, parts[1:], nil
|
return c, parts[1:], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath Path) (node.Node, []string, error) {
|
||||||
|
c, p, err := SplitAbsPath(fpath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
nd, err := r.DAG.Get(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for len(p) > 0 {
|
||||||
|
val, rest, err := nd.Resolve(p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch val := val.(type) {
|
||||||
|
case *node.Link:
|
||||||
|
next, err := val.GetNode(ctx, r.DAG)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
nd = next
|
||||||
|
p = rest
|
||||||
|
default:
|
||||||
|
return nd, p, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nd, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ResolvePath fetches the node for given path. It returns the last item
|
// ResolvePath fetches the node for given path. It returns the last item
|
||||||
// returned by ResolvePathComponents.
|
// returned by ResolvePathComponents.
|
||||||
func (s *Resolver) ResolvePath(ctx context.Context, fpath Path) (node.Node, error) {
|
func (s *Resolver) ResolvePath(ctx context.Context, fpath Path) (node.Node, error) {
|
||||||
|
Reference in New Issue
Block a user