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 {
// Pinner interface defines how the simple.Reprovider wants to interact
// with a Pinning service
type Pinner interface {
DirectKeys() []cid.Cid
RecursiveKeys() []cid.Cid
DirectKeys(ctx context.Context) ([]cid.Cid, error)
RecursiveKeys(ctx context.Context) ([]cid.Cid, error)
}
// NewPinnedProvider returns provider supplying pinned keys
......@@ -208,11 +208,21 @@ func pinSet(ctx context.Context, pinning Pinner, dag ipld.DAGService, onlyRoots
defer cancel()
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)
}
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 {
set.Visitor(ctx)(key)
} else {
......
......@@ -100,12 +100,12 @@ type mockPinner struct {
direct []cid.Cid
}
func (mp *mockPinner) DirectKeys() []cid.Cid {
return mp.direct
func (mp *mockPinner) DirectKeys(ctx context.Context) ([]cid.Cid, error) {
return mp.direct, nil
}
func (mp *mockPinner) RecursiveKeys() []cid.Cid {
return mp.recursive
func (mp *mockPinner) RecursiveKeys(ctx context.Context) ([]cid.Cid, error) {
return mp.recursive, nil
}
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