@cryptotaxi247 / kubo / commits / f20db0cce

fix(pin): wait till after fetching to remove direct pin

Otherwise, we could abort while fetching the graph and stay in a state where the direct pin is removed. fixes #4650

Steven Allen committed Oct 8, 2019 at 16:50 UTC f20db0cce81818df8ecd314c469ffb40f69b483d
2 files changed +9 -4
pin/pin.go
-3
@@ -225,9 +225,6 @@ func (p *pinner) Pin(ctx context.Context, node ipld.Node, recurse bool) error {
225 return nil
226 }
227
228 - if p.directPin.Has(c) {
229 - p.directPin.Remove(c)
230 - }
228 p.lock.Unlock()
229 // fetch entire graph
230 err := mdag.FetchGraph(ctx, c, p.dserv)
test/sharness/t0081-repo-pinning.sh
+9 -1
@@ -237,13 +237,21 @@ test_expect_success "some are no longer there" '
237 test_must_fail ipfs ls "$HASH_DIR3"
238 '
239
240 +test_launch_ipfs_daemon --offline
241 test_expect_success "recursive pin fails without objects" '
241 - ipfs pin rm -r=false "$HASH_DIR1" &&
242 test_must_fail ipfs pin add -r "$HASH_DIR1" 2>err_expected8 &&
243 grep "pin: merkledag: not found" err_expected8 ||
244 test_fsh cat err_expected8
245 '
246
247 +# Regression test for https://github.com/ipfs/go-ipfs/issues/4650
248 +# This test requires the daemon. Otherwise, the pin changes are reverted when
249 +# the pin fails in the previous test.
250 +test_expect_success "failed recursive pin does not remove direct pin" '
251 + test_pin_flag "$HASH_DIR1" direct true
252 +'
253 +test_kill_ipfs_daemon
254 +
255 test_expect_success "test add nopin file" '
256 echo "test nopin data" > test_nopin_data &&
257 NOPINHASH=$(ipfs add -q --pin=false test_nopin_data) &&