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
5158c31c
Commit
5158c31c
authored
Oct 14, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract node interface
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
3c44991b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
resolver.go
resolver.go
+5
-4
resolver_test.go
resolver_test.go
+4
-3
No files found.
resolver.go
View file @
5158c31c
...
...
@@ -11,6 +11,7 @@ import (
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid
"gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
node
"gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
)
var
log
=
logging
.
Logger
(
"path"
)
...
...
@@ -61,7 +62,7 @@ func SplitAbsPath(fpath Path) (*cid.Cid, []string, error) {
// ResolvePath fetches the node for given path. It returns the last item
// returned by ResolvePathComponents.
func
(
s
*
Resolver
)
ResolvePath
(
ctx
context
.
Context
,
fpath
Path
)
(
merkledag
.
Node
,
error
)
{
func
(
s
*
Resolver
)
ResolvePath
(
ctx
context
.
Context
,
fpath
Path
)
(
node
.
Node
,
error
)
{
// validate path
if
err
:=
fpath
.
IsValid
();
err
!=
nil
{
return
nil
,
err
...
...
@@ -77,7 +78,7 @@ func (s *Resolver) ResolvePath(ctx context.Context, fpath Path) (merkledag.Node,
// ResolvePathComponents fetches the nodes for each segment of the given path.
// It uses the first path component as a hash (key) of the first node, then
// resolves all other components walking the links, with ResolveLinks.
func
(
s
*
Resolver
)
ResolvePathComponents
(
ctx
context
.
Context
,
fpath
Path
)
([]
merkledag
.
Node
,
error
)
{
func
(
s
*
Resolver
)
ResolvePathComponents
(
ctx
context
.
Context
,
fpath
Path
)
([]
node
.
Node
,
error
)
{
h
,
parts
,
err
:=
SplitAbsPath
(
fpath
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -99,9 +100,9 @@ func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]mer
//
// ResolveLinks(nd, []string{"foo", "bar", "baz"})
// would retrieve "baz" in ("bar" in ("foo" in nd.Links).Links).Links
func
(
s
*
Resolver
)
ResolveLinks
(
ctx
context
.
Context
,
ndd
merkledag
.
Node
,
names
[]
string
)
([]
merkledag
.
Node
,
error
)
{
func
(
s
*
Resolver
)
ResolveLinks
(
ctx
context
.
Context
,
ndd
node
.
Node
,
names
[]
string
)
([]
node
.
Node
,
error
)
{
result
:=
make
([]
merkledag
.
Node
,
0
,
len
(
names
)
+
1
)
result
:=
make
([]
node
.
Node
,
0
,
len
(
names
)
+
1
)
result
=
append
(
result
,
ndd
)
nd
:=
ndd
// dup arg workaround
...
...
resolver_test.go
View file @
5158c31c
package
path_test
import
(
"context"
"fmt"
"testing"
context
"context"
merkledag
"github.com/ipfs/go-ipfs/merkledag"
dagmock
"github.com/ipfs/go-ipfs/merkledag/test"
path
"github.com/ipfs/go-ipfs/path"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
node
"gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
util
"gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
)
...
...
@@ -39,7 +40,7 @@ func TestRecurivePathResolution(t *testing.T) {
t
.
Fatal
(
err
)
}
for
_
,
n
:=
range
[]
merkledag
.
Node
{
a
,
b
,
c
}
{
for
_
,
n
:=
range
[]
node
.
Node
{
a
,
b
,
c
}
{
_
,
err
=
dagService
.
Add
(
n
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
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