mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 19:24:14 +08:00
path: simplify ResolveToLastNode
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
@ -70,7 +70,10 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (ipld
|
|||||||
|
|
||||||
for len(p) > 0 {
|
for len(p) > 0 {
|
||||||
lnk, rest, err := r.ResolveOnce(ctx, r.DAG, nd, p)
|
lnk, rest, err := r.ResolveOnce(ctx, r.DAG, nd, p)
|
||||||
if lnk != nil {
|
if lnk == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -81,13 +84,21 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (ipld
|
|||||||
}
|
}
|
||||||
nd = next
|
nd = next
|
||||||
p = rest
|
p = rest
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(p) == 0 {
|
||||||
|
return nd, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Confirm the path exists within the object
|
||||||
val, rest, err := nd.Resolve(p)
|
val, rest, err := nd.Resolve(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(rest) > 0 {
|
||||||
|
return nil, nil, errors.New("path failed to resolve fully")
|
||||||
|
}
|
||||||
switch val.(type) {
|
switch val.(type) {
|
||||||
case *ipld.Link:
|
case *ipld.Link:
|
||||||
return nil, nil, errors.New("inconsistent ResolveOnce / nd.Resolve")
|
return nil, nil, errors.New("inconsistent ResolveOnce / nd.Resolve")
|
||||||
@ -96,9 +107,6 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (ipld
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (r *Resolver) ResolvePath(ctx context.Context, fpath path.Path) (ipld.Node, error) {
|
func (r *Resolver) ResolvePath(ctx context.Context, fpath path.Path) (ipld.Node, error) {
|
||||||
|
Reference in New Issue
Block a user