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
34251f0e
Unverified
Commit
34251f0e
authored
Aug 06, 2018
by
Whyrusleeping
Committed by
GitHub
Aug 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1 from ipfs/fix/resolve-last-cid
fix: don't dag.Get in ResolveToLastNode when not needed
parents
ca783f9d
29e9e4c0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
5 deletions
+45
-5
resolver/resolver.go
resolver/resolver.go
+9
-5
resolver/resolver_test.go
resolver/resolver_test.go
+36
-0
No files found.
resolver/resolver.go
View file @
34251f0e
...
...
@@ -55,14 +55,18 @@ func NewBasicResolver(ds ipld.DAGService) *Resolver {
}
}
// ResolveToLastNode walks the given path and returns the
ipld.N
ode
// referenced by the
last element in it.
func
(
r
*
Resolver
)
ResolveToLastNode
(
ctx
context
.
Context
,
fpath
path
.
Path
)
(
ipld
.
Node
,
[]
string
,
error
)
{
// ResolveToLastNode walks the given path and returns the
cid of the last n
ode
// referenced by the
path
func
(
r
*
Resolver
)
ResolveToLastNode
(
ctx
context
.
Context
,
fpath
path
.
Path
)
(
*
cid
.
Cid
,
[]
string
,
error
)
{
c
,
p
,
err
:=
path
.
SplitAbsPath
(
fpath
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
if
len
(
p
)
==
0
{
return
c
,
nil
,
nil
}
nd
,
err
:=
r
.
DAG
.
Get
(
ctx
,
c
)
if
err
!=
nil
{
return
nil
,
nil
,
err
...
...
@@ -91,7 +95,7 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (ipld
}
if
len
(
p
)
==
0
{
return
nd
,
nil
,
nil
return
nd
.
Cid
()
,
nil
,
nil
}
// Confirm the path exists within the object
...
...
@@ -107,7 +111,7 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (ipld
case
*
ipld
.
Link
:
return
nil
,
nil
,
errors
.
New
(
"inconsistent ResolveOnce / nd.Resolve"
)
default
:
return
nd
,
p
,
nil
return
nd
.
Cid
()
,
p
,
nil
}
}
...
...
resolver/resolver_test.go
View file @
34251f0e
...
...
@@ -69,4 +69,40 @@ func TestRecurivePathResolution(t *testing.T) {
"recursive path resolution failed for %s: %s != %s"
,
p
.
String
(),
key
.
String
(),
cKey
.
String
()))
}
rCid
,
rest
,
err
:=
resolver
.
ResolveToLastNode
(
ctx
,
p
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
rest
)
!=
0
{
t
.
Error
(
"expected rest to be empty"
)
}
if
rCid
.
String
()
!=
cKey
.
String
()
{
t
.
Fatal
(
fmt
.
Errorf
(
"ResolveToLastNode failed for %s: %s != %s"
,
p
.
String
(),
rCid
.
String
(),
cKey
.
String
()))
}
p2
,
err
:=
path
.
FromSegments
(
"/ipfs/"
,
aKey
.
String
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
rCid
,
rest
,
err
=
resolver
.
ResolveToLastNode
(
ctx
,
p2
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
rest
)
!=
0
{
t
.
Error
(
"expected rest to be empty"
)
}
if
rCid
.
String
()
!=
aKey
.
String
()
{
t
.
Fatal
(
fmt
.
Errorf
(
"ResolveToLastNode failed for %s: %s != %s"
,
p
.
String
(),
rCid
.
String
(),
cKey
.
String
()))
}
}
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