pin: fix pin update X Y where X==Y
We were pining Y then removing the pin for X. When X == Y, we'd remove the new pin. fixes #6648
Steven Allen committed
Sep 23, 2019 at 16:29 UTC
c69e347be098c84becd0aef86550b1ef533494fe
2 files changed
+11
pin/pin.go
+8
@@ -516,6 +516,14 @@ func (p *pinner) RecursiveKeys() []cid.Cid {
516
// this is more efficient than simply pinning the new one and unpinning the
517
// old one
518
func (p *pinner) Update(ctx context.Context, from, to cid.Cid, unpin bool) error {
519
+ if from == to {
520
+ // Nothing to do. Don't remove this check or we'll end up
521
+ // _removing_ the pin.
522
+ //
523
+ // See #6648
524
+ return nil
525
+ }
526
+
527
p.lock.Lock()
528
defer p.lock.Unlock()
529
test/sharness/t0085-pins.sh
+3
@@ -100,6 +100,9 @@ test_pins() {
100
ipfs pin ls $BASE_ARGS > after_update &&
101
test_must_fail grep -q "$HASH_A" after_update &&
102
test_should_contain "$HASH_B" after_update &&
103
+ ipfs pin update --unpin=true "$HASH_B" "$HASH_B" &&
104
+ ipfs pin ls $LS_ARGS $BASE_ARGS > after_idempotent_update &&
105
+ test_should_contain "$HASH_B" after_idempotent_update &&
106
ipfs pin rm "$HASH_B"
107
'
108
}