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
interface-go-dms3-core
Commits
f976af7b
Unverified
Commit
f976af7b
authored
Nov 27, 2019
by
Michael Muré
Committed by
Michael Muré
Nov 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: make the CoreAPI expose a streaming pin interface
parent
7bbf5bb0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
14 deletions
+34
-14
pin.go
pin.go
+4
-1
tests/block.go
tests/block.go
+1
-1
tests/pin.go
tests/pin.go
+28
-11
tests/unixfs.go
tests/unixfs.go
+1
-1
No files found.
pin.go
View file @
f976af7b
...
...
@@ -14,6 +14,9 @@ type Pin interface {
// Type of the pin
Type
()
string
// if not nil, an error happened. Everything else should be ignored.
Err
()
error
}
// PinStatus holds information about pin health
...
...
@@ -41,7 +44,7 @@ type PinAPI interface {
Add
(
context
.
Context
,
path
.
Path
,
...
options
.
PinAddOption
)
error
// Ls returns list of pinned objects on this node
Ls
(
context
.
Context
,
...
options
.
PinLsOption
)
(
[]
Pin
,
error
)
Ls
(
context
.
Context
,
...
options
.
PinLsOption
)
(
<-
chan
Pin
,
error
)
// Rm removes pin for object specified by the path
Rm
(
context
.
Context
,
path
.
Path
,
...
options
.
PinRmOption
)
error
...
...
tests/block.go
View file @
f976af7b
...
...
@@ -225,7 +225,7 @@ func (tp *TestSuite) TestBlockPin(t *testing.T) {
t
.
Fatal
(
err
)
}
pins
,
err
:=
api
.
Pin
()
.
Ls
(
ctx
)
pins
,
err
:=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
)
)
if
err
!=
nil
{
return
}
...
...
tests/pin.go
View file @
f976af7b
...
...
@@ -67,7 +67,7 @@ func (tp *TestSuite) TestPinSimple(t *testing.T) {
t
.
Fatal
(
err
)
}
list
,
err
:=
api
.
Pin
()
.
Ls
(
ctx
)
list
,
err
:=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
)
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -89,7 +89,7 @@ func (tp *TestSuite) TestPinSimple(t *testing.T) {
t
.
Fatal
(
err
)
}
list
,
err
=
api
.
Pin
()
.
Ls
(
ctx
)
list
,
err
=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
)
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -141,7 +141,7 @@ func (tp *TestSuite) TestPinRecursive(t *testing.T) {
t
.
Fatal
(
err
)
}
list
,
err
:=
api
.
Pin
()
.
Ls
(
ctx
)
list
,
err
:=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
)
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -150,7 +150,7 @@ func (tp *TestSuite) TestPinRecursive(t *testing.T) {
t
.
Errorf
(
"unexpected pin list len: %d"
,
len
(
list
))
}
list
,
err
=
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Direct
())
list
,
err
=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Direct
())
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -163,7 +163,7 @@ func (tp *TestSuite) TestPinRecursive(t *testing.T) {
t
.
Errorf
(
"unexpected path, %s != %s"
,
list
[
0
]
.
Path
()
.
String
(),
path
.
IpfsPath
(
nd2
.
Cid
())
.
String
())
}
list
,
err
=
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Recursive
())
list
,
err
=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Recursive
())
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -176,7 +176,7 @@ func (tp *TestSuite) TestPinRecursive(t *testing.T) {
t
.
Errorf
(
"unexpected path, %s != %s"
,
list
[
0
]
.
Path
()
.
String
(),
path
.
IpldPath
(
nd3
.
Cid
())
.
String
())
}
list
,
err
=
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Indirect
())
list
,
err
=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Indirect
())
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -390,21 +390,21 @@ func getThreeChainedNodes(t *testing.T, ctx context.Context, api iface.CoreAPI,
func
assertPinTypes
(
t
*
testing
.
T
,
ctx
context
.
Context
,
api
iface
.
CoreAPI
,
recusive
,
direct
,
indirect
[]
cidContainer
)
{
assertPinLsAllConsistency
(
t
,
ctx
,
api
)
list
,
err
:=
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Recursive
())
list
,
err
:=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Recursive
())
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
assertPinCids
(
t
,
list
,
recusive
...
)
list
,
err
=
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Direct
())
list
,
err
=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Direct
())
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
assertPinCids
(
t
,
list
,
direct
...
)
list
,
err
=
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Indirect
())
list
,
err
=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
,
opt
.
Pin
.
Type
.
Indirect
())
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -454,7 +454,7 @@ func assertPinCids(t *testing.T, pins []iface.Pin, cids ...cidContainer) {
// assertPinLsAllConsistency verifies that listing all pins gives the same result as listing the pin types individually
func
assertPinLsAllConsistency
(
t
*
testing
.
T
,
ctx
context
.
Context
,
api
iface
.
CoreAPI
)
{
t
.
Helper
()
allPins
,
err
:=
api
.
Pin
()
.
Ls
(
ctx
)
allPins
,
err
:=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
)
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -485,7 +485,7 @@ func assertPinLsAllConsistency(t *testing.T, ctx context.Context, api iface.Core
}
for
typeStr
,
pinProps
:=
range
typeMap
{
pins
,
err
:=
api
.
Pin
()
.
Ls
(
ctx
,
pinProps
.
PinLsOption
)
pins
,
err
:=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
,
pinProps
.
PinLsOption
)
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -505,3 +505,20 @@ func assertPinLsAllConsistency(t *testing.T, ctx context.Context, api iface.Core
}
}
}
func
accPins
(
pins
<-
chan
iface
.
Pin
,
err
error
)
([]
iface
.
Pin
,
error
)
{
if
err
!=
nil
{
return
nil
,
err
}
var
result
[]
iface
.
Pin
for
pin
:=
range
pins
{
if
pin
.
Err
()
!=
nil
{
return
nil
,
pin
.
Err
()
}
result
=
append
(
result
,
pin
)
}
return
result
,
nil
}
tests/unixfs.go
View file @
f976af7b
...
...
@@ -542,7 +542,7 @@ func (tp *TestSuite) TestAddPinned(t *testing.T) {
t
.
Fatal
(
err
)
}
pins
,
err
:=
api
.
Pin
()
.
Ls
(
ctx
)
pins
,
err
:=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
)
)
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