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-dms3
Commits
e5def26b
Commit
e5def26b
authored
Feb 16, 2017
by
Jeromy Johnson
Committed by
GitHub
Feb 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3687 from ipfs/feat/sub-obj-dag-get
Feat/sub obj dag get
parents
8c521b68
cb611c88
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
8 deletions
+72
-8
core/commands/dag/dag.go
core/commands/dag/dag.go
+13
-3
merkledag/merkledag.go
merkledag/merkledag.go
+1
-1
package.json
package.json
+2
-2
path/resolver.go
path/resolver.go
+33
-0
test/sharness/t0053-dag.sh
test/sharness/t0053-dag.sh
+23
-2
No files found.
core/commands/dag/dag.go
View file @
e5def26b
...
...
@@ -10,8 +10,8 @@ import (
path
"github.com/ipfs/go-ipfs/path"
cid
"gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
ipldcbor
"gx/ipfs/QmWcQMNruWC3wphK1L6zEcV4MZBJqfsNKSRFcuo4AsNk4k/go-ipld-cbor"
node
"gx/ipfs/QmYDscK7dmdo2GZ9aumS8s5auUUAH5mR1jvj5pYhWusfK7/go-ipld-node"
ipldcbor
"gx/ipfs/QmdaC21UyoyN3t9QdapHZfsaUo3mqVf5p4CEuFaYVFqwap/go-ipld-cbor"
)
var
DagCmd
=
&
cmds
.
Command
{
...
...
@@ -137,13 +137,23 @@ var DagGetCmd = &cmds.Command{
return
}
obj
,
err
:=
n
.
Resolver
.
Resolve
Path
(
req
.
Context
(),
p
)
obj
,
rem
,
err
:=
n
.
Resolver
.
Resolve
ToLastNode
(
req
.
Context
(),
p
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
res
.
SetOutput
(
obj
)
var
out
interface
{}
=
obj
if
len
(
rem
)
>
0
{
final
,
_
,
err
:=
obj
.
Resolve
(
rem
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
out
=
final
}
res
.
SetOutput
(
out
)
},
}
...
...
merkledag/merkledag.go
View file @
e5def26b
...
...
@@ -13,8 +13,8 @@ import (
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid
"gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
ipldcbor
"gx/ipfs/QmWcQMNruWC3wphK1L6zEcV4MZBJqfsNKSRFcuo4AsNk4k/go-ipld-cbor"
node
"gx/ipfs/QmYDscK7dmdo2GZ9aumS8s5auUUAH5mR1jvj5pYhWusfK7/go-ipld-node"
ipldcbor
"gx/ipfs/QmdaC21UyoyN3t9QdapHZfsaUo3mqVf5p4CEuFaYVFqwap/go-ipld-cbor"
)
var
log
=
logging
.
Logger
(
"merkledag"
)
...
...
package.json
View file @
e5def26b
...
...
@@ -267,9 +267,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
WcQMNruWC3wphK1L6zEcV4MZBJqfsNKSRFcuo4AsNk4k
"
,
"hash"
:
"Qm
daC21UyoyN3t9QdapHZfsaUo3mqVf5p4CEuFaYVFqwap
"
,
"name"
:
"go-ipld-cbor"
,
"version"
:
"1.2.
0
"
"version"
:
"1.2.
1
"
},
{
"author"
:
"lgierth"
,
...
...
path/resolver.go
View file @
e5def26b
...
...
@@ -73,6 +73,39 @@ func SplitAbsPath(fpath Path) (*cid.Cid, []string, error) {
return
c
,
parts
[
1
:
],
nil
}
func
(
r
*
Resolver
)
ResolveToLastNode
(
ctx
context
.
Context
,
fpath
Path
)
(
node
.
Node
,
[]
string
,
error
)
{
c
,
p
,
err
:=
SplitAbsPath
(
fpath
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
nd
,
err
:=
r
.
DAG
.
Get
(
ctx
,
c
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
for
len
(
p
)
>
0
{
val
,
rest
,
err
:=
nd
.
Resolve
(
p
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
switch
val
:=
val
.
(
type
)
{
case
*
node
.
Link
:
next
,
err
:=
val
.
GetNode
(
ctx
,
r
.
DAG
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
nd
=
next
p
=
rest
default
:
return
nd
,
p
,
nil
}
}
return
nd
,
nil
,
nil
}
// ResolvePath fetches the node for given path. It returns the last item
// returned by ResolvePathComponents.
func
(
s
*
Resolver
)
ResolvePath
(
ctx
context
.
Context
,
fpath
Path
)
(
node
.
Node
,
error
)
{
...
...
test/sharness/t0053-dag.sh
View file @
e5def26b
...
...
@@ -22,7 +22,7 @@ test_expect_success "make a few test files" '
'
test_expect_success
"make an ipld object in json"
'
printf "{\"hello\":\"world\",\"cats\":[{\"/\":\"%s\"},{\"water\":{\"/\":\"%s\"}}],\"magic\":{\"/\":\"%s\"}}" $HASH1 $HASH2 $HASH3 > ipld_object
printf "{\"hello\":\"world\",\"cats\":[{\"/\":\"%s\"},{\"water\":{\"/\":\"%s\"}}],\"magic\":{\"/\":\"%s\"}
,\"sub\":{\"dict\":\"ionary\",\"beep\":[0,\"bop\"]}
}" $HASH1 $HASH2 $HASH3 > ipld_object
'
test_dag_cmd
()
{
...
...
@@ -31,7 +31,7 @@ test_dag_cmd() {
'
test_expect_success
"output looks correct"
'
EXPHASH="zdpuA
zn7KZcQmKJvpEM1DgHXaybVj7mRP4ZMrkW94taYEuZHp
"
EXPHASH="zdpuA
sXfkHapxohc8LtsCzYiAsy84ESqKRD8eWuY64tt9r2CE
"
test $EXPHASH = $IPLDHASH
'
...
...
@@ -47,6 +47,27 @@ test_dag_cmd() {
test_cmp file3 out3
'
test_expect_success
"resolving sub-objects works"
'
ipfs dag get $IPLDHASH/hello > sub1 &&
ipfs dag get $IPLDHASH/sub > sub2 &&
ipfs dag get $IPLDHASH/sub/beep > sub3 &&
ipfs dag get $IPLDHASH/sub/beep/0 > sub4 &&
ipfs dag get $IPLDHASH/sub/beep/1 > sub5
'
test_expect_success
"sub-objects look right"
'
echo "\"world\"" > sub1_exp &&
test_cmp sub1_exp sub1 &&
echo "{\"beep\":[0,\"bop\"],\"dict\":\"ionary\"}" > sub2_exp &&
test_cmp sub2_exp sub2 &&
echo "[0,\"bop\"]" > sub3_exp &&
test_cmp sub3_exp sub3 &&
echo "0" > sub4_exp &&
test_cmp sub4_exp sub4 &&
echo "\"bop\"" > sub5_exp &&
test_cmp sub5_exp sub5
'
test_expect_success
"can pin cbor object"
'
ipfs pin add $EXPHASH
'
...
...
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