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
5b015d97
Commit
5b015d97
authored
Sep 07, 2018
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gx update and fix code to use new Cid type
parent
c9cfadd2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
19 deletions
+19
-19
package.json
package.json
+6
-6
path.go
path.go
+4
-4
resolver/resolver.go
resolver/resolver.go
+9
-9
No files found.
package.json
View file @
5b015d97
...
...
@@ -9,21 +9,21 @@
"gxDependencies"
:
[
{
"author"
:
"why"
,
"hash"
:
"Qm
Nr4E8z9bGTztvHJktp7uQaMdx9p3r9Asrq6eYk7iCh4a
"
,
"hash"
:
"Qm
URqt1jB9Yu3X4Tr9WQJf36QGN7vi8mGTzjnX2ij1CJwC
"
,
"name"
:
"go-merkledag"
,
"version"
:
"1.
0.14
"
"version"
:
"1.
1.0
"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
X5CsuHyVZeTLxgRSYkgLSDQKb9UjE8xnhQzCEJWWWFsC
"
,
"hash"
:
"Qm
dDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL
"
,
"name"
:
"go-ipld-format"
,
"version"
:
"0.
5.8
"
"version"
:
"0.
6.0
"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
ZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb
"
,
"hash"
:
"Qm
PSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7
"
,
"name"
:
"go-cid"
,
"version"
:
"0.
8
.0"
"version"
:
"0.
9
.0"
},
{
"hash"
:
"QmRREK2CAZ5Re2Bd9zZFG6FeYDppUWt5cMgsoUEp3ktgSr"
,
...
...
path.go
View file @
5b015d97
...
...
@@ -36,7 +36,7 @@ func FromString(s string) Path {
}
// FromCid safely converts a cid.Cid type to a Path type.
func
FromCid
(
c
*
cid
.
Cid
)
Path
{
func
FromCid
(
c
cid
.
Cid
)
Path
{
return
Path
(
"/ipfs/"
+
c
.
String
())
}
...
...
@@ -160,7 +160,7 @@ func SplitList(pth string) []string {
// SplitAbsPath clean up and split fpath. It extracts the first component (which
// must be a Multihash) and return it separately.
func
SplitAbsPath
(
fpath
Path
)
(
*
cid
.
Cid
,
[]
string
,
error
)
{
func
SplitAbsPath
(
fpath
Path
)
(
cid
.
Cid
,
[]
string
,
error
)
{
parts
:=
fpath
.
Segments
()
if
parts
[
0
]
==
"ipfs"
||
parts
[
0
]
==
"ipld"
{
parts
=
parts
[
1
:
]
...
...
@@ -168,13 +168,13 @@ func SplitAbsPath(fpath Path) (*cid.Cid, []string, error) {
// if nothing, bail.
if
len
(
parts
)
==
0
{
return
nil
,
nil
,
ErrNoComponents
return
cid
.
Cid
{}
,
nil
,
ErrNoComponents
}
c
,
err
:=
cid
.
Decode
(
parts
[
0
])
// first element in the path is a cid
if
err
!=
nil
{
return
nil
,
nil
,
err
return
cid
.
Cid
{}
,
nil
,
err
}
return
c
,
parts
[
1
:
],
nil
...
...
resolver/resolver.go
View file @
5b015d97
...
...
@@ -25,7 +25,7 @@ var ErrNoComponents = errors.New(
// ErrNoLink is returned when a link is not found in a path
type
ErrNoLink
struct
{
Name
string
Node
*
cid
.
Cid
Node
cid
.
Cid
}
// Error implements the Error interface for ErrNoLink with a useful
...
...
@@ -57,10 +57,10 @@ func NewBasicResolver(ds ipld.DAGService) *Resolver {
// ResolveToLastNode walks the given path and returns the cid of the last node
// referenced by the path
func
(
r
*
Resolver
)
ResolveToLastNode
(
ctx
context
.
Context
,
fpath
path
.
Path
)
(
*
cid
.
Cid
,
[]
string
,
error
)
{
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
return
cid
.
Cid
{}
,
nil
,
err
}
if
len
(
p
)
==
0
{
...
...
@@ -69,7 +69,7 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (*cid
nd
,
err
:=
r
.
DAG
.
Get
(
ctx
,
c
)
if
err
!=
nil
{
return
nil
,
nil
,
err
return
cid
.
Cid
{}
,
nil
,
err
}
for
len
(
p
)
>
0
{
...
...
@@ -83,12 +83,12 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (*cid
}
if
err
!=
nil
{
return
nil
,
nil
,
err
return
cid
.
Cid
{}
,
nil
,
err
}
next
,
err
:=
lnk
.
GetNode
(
ctx
,
r
.
DAG
)
if
err
!=
nil
{
return
nil
,
nil
,
err
return
cid
.
Cid
{}
,
nil
,
err
}
nd
=
next
p
=
rest
...
...
@@ -101,15 +101,15 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (*cid
// Confirm the path exists within the object
val
,
rest
,
err
:=
nd
.
Resolve
(
p
)
if
err
!=
nil
{
return
nil
,
nil
,
err
return
cid
.
Cid
{}
,
nil
,
err
}
if
len
(
rest
)
>
0
{
return
nil
,
nil
,
errors
.
New
(
"path failed to resolve fully"
)
return
cid
.
Cid
{}
,
nil
,
errors
.
New
(
"path failed to resolve fully"
)
}
switch
val
.
(
type
)
{
case
*
ipld
.
Link
:
return
nil
,
nil
,
errors
.
New
(
"inconsistent ResolveOnce / nd.Resolve"
)
return
cid
.
Cid
{}
,
nil
,
errors
.
New
(
"inconsistent ResolveOnce / nd.Resolve"
)
default
:
return
nd
.
Cid
(),
p
,
nil
}
...
...
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