Unverified Commit 1586f38d authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #16 from MichaelMure/pinner-ctx-err

adapt to go-ipfs Pinner interface changes with context and error
parents a51bdf9d f2597dc7
...@@ -171,8 +171,8 @@ func NewBlockstoreProvider(bstore blocks.Blockstore) KeyChanFunc { ...@@ -171,8 +171,8 @@ func NewBlockstoreProvider(bstore blocks.Blockstore) KeyChanFunc {
// Pinner interface defines how the simple.Reprovider wants to interact // Pinner interface defines how the simple.Reprovider wants to interact
// with a Pinning service // with a Pinning service
type Pinner interface { type Pinner interface {
DirectKeys() []cid.Cid DirectKeys(ctx context.Context) ([]cid.Cid, error)
RecursiveKeys() []cid.Cid RecursiveKeys(ctx context.Context) ([]cid.Cid, error)
} }
// NewPinnedProvider returns provider supplying pinned keys // NewPinnedProvider returns provider supplying pinned keys
...@@ -208,11 +208,21 @@ func pinSet(ctx context.Context, pinning Pinner, dag ipld.DAGService, onlyRoots ...@@ -208,11 +208,21 @@ func pinSet(ctx context.Context, pinning Pinner, dag ipld.DAGService, onlyRoots
defer cancel() defer cancel()
defer close(set.New) defer close(set.New)
for _, key := range pinning.DirectKeys() { dkeys, err := pinning.DirectKeys(ctx)
if err != nil {
logR.Errorf("reprovide direct pins: %s", err)
return
}
for _, key := range dkeys {
set.Visitor(ctx)(key) set.Visitor(ctx)(key)
} }
for _, key := range pinning.RecursiveKeys() { rkeys, err := pinning.RecursiveKeys(ctx)
if err != nil {
logR.Errorf("reprovide indirect pins: %s", err)
return
}
for _, key := range rkeys {
if onlyRoots { if onlyRoots {
set.Visitor(ctx)(key) set.Visitor(ctx)(key)
} else { } else {
......
...@@ -100,12 +100,12 @@ type mockPinner struct { ...@@ -100,12 +100,12 @@ type mockPinner struct {
direct []cid.Cid direct []cid.Cid
} }
func (mp *mockPinner) DirectKeys() []cid.Cid { func (mp *mockPinner) DirectKeys(ctx context.Context) ([]cid.Cid, error) {
return mp.direct return mp.direct, nil
} }
func (mp *mockPinner) RecursiveKeys() []cid.Cid { func (mp *mockPinner) RecursiveKeys(ctx context.Context) ([]cid.Cid, error) {
return mp.recursive return mp.recursive, nil
} }
func TestReprovidePinned(t *testing.T) { func TestReprovidePinned(t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment