Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-path
Commits
797c0c4f
Commit
797c0c4f
authored
Jul 23, 2018
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path: simplify ResolveToLastNode
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
53c23438
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
19 deletions
+27
-19
resolver/resolver.go
resolver/resolver.go
+27
-19
No files found.
resolver/resolver.go
View file @
797c0c4f
...
...
@@ -70,33 +70,41 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (ipld
for
len
(
p
)
>
0
{
lnk
,
rest
,
err
:=
r
.
ResolveOnce
(
ctx
,
r
.
DAG
,
nd
,
p
)
if
lnk
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
}
next
,
err
:=
lnk
.
GetNode
(
ctx
,
r
.
DAG
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
nd
=
next
p
=
rest
continue
if
lnk
==
nil
{
break
}
val
,
rest
,
err
:=
nd
.
Resolve
(
p
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
switch
val
.
(
type
)
{
case
*
ipld
.
Link
:
return
nil
,
nil
,
errors
.
New
(
"inconsistent ResolveOnce / nd.Resolve"
)
default
:
return
nd
,
p
,
nil
next
,
err
:=
lnk
.
GetNode
(
ctx
,
r
.
DAG
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
nd
=
next
p
=
rest
}
return
nd
,
nil
,
nil
if
len
(
p
)
==
0
{
return
nd
,
nil
,
nil
}
// Confirm the path exists within the object
val
,
rest
,
err
:=
nd
.
Resolve
(
p
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
if
len
(
rest
)
>
0
{
return
nil
,
nil
,
errors
.
New
(
"path failed to resolve fully"
)
}
switch
val
.
(
type
)
{
case
*
ipld
.
Link
:
return
nil
,
nil
,
errors
.
New
(
"inconsistent ResolveOnce / nd.Resolve"
)
default
:
return
nd
,
p
,
nil
}
}
// ResolvePath fetches the node for given path. It returns the last item
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment