From ab69f0fb4d85e7a133c87138953b3975bec20f8b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 2 Oct 2018 14:36:12 -0700 Subject: [PATCH 1/2] take the pinlock when updating pins License: MIT Signed-off-by: Steven Allen --- core/coreapi/pin.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/coreapi/pin.go b/core/coreapi/pin.go index c99224cb0..0452c3759 100644 --- a/core/coreapi/pin.go +++ b/core/coreapi/pin.go @@ -67,6 +67,8 @@ func (api *PinAPI) Update(ctx context.Context, from coreiface.Path, to coreiface return err } + defer api.node.Blockstore.PinLock().Unlock() + fp, err := api.core().ResolvePath(ctx, from) if err != nil { return err From bf654ea4f879c7bc75c52a6fcacda24fe1214dc9 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 2 Oct 2018 15:39:32 -0700 Subject: [PATCH 2/2] defer the pinlock till we actually need it License: MIT Signed-off-by: Steven Allen --- core/coreapi/pin.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/coreapi/pin.go b/core/coreapi/pin.go index 0452c3759..ad6dfe922 100644 --- a/core/coreapi/pin.go +++ b/core/coreapi/pin.go @@ -22,13 +22,13 @@ func (api *PinAPI) Add(ctx context.Context, p coreiface.Path, opts ...caopts.Pin return err } - defer api.node.Blockstore.PinLock().Unlock() - rp, err := api.core().ResolvePath(ctx, p) if err != nil { return err } + defer api.node.Blockstore.PinLock().Unlock() + _, err = corerepo.Pin(api.node, api.core(), ctx, []string{rp.Cid().String()}, settings.Recursive) if err != nil { return err @@ -67,8 +67,6 @@ func (api *PinAPI) Update(ctx context.Context, from coreiface.Path, to coreiface return err } - defer api.node.Blockstore.PinLock().Unlock() - fp, err := api.core().ResolvePath(ctx, from) if err != nil { return err @@ -79,6 +77,8 @@ func (api *PinAPI) Update(ctx context.Context, from coreiface.Path, to coreiface return err } + defer api.node.Blockstore.PinLock().Unlock() + err = api.node.Pinning.Update(ctx, fp.Cid(), tp.Cid(), settings.Unpin) if err != nil { return err