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
6722a3853506b35df2b47ebede8f6ff266eaac9f
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
@@ -101,6 +101,9 @@ test_pins() {
101
ipfs pin ls $LS_ARGS $BASE_ARGS > after_update &&
102
test_must_fail grep -q "$HASH_A" after_update &&
103
test_should_contain "$HASH_B" after_update &&
104
+ ipfs pin update --unpin=true "$HASH_B" "$HASH_B" &&
105
+ ipfs pin ls $LS_ARGS $BASE_ARGS > after_idempotent_update &&
106
+ test_should_contain "$HASH_B" after_idempotent_update &&
107
ipfs pin rm "$HASH_B"
108
'
109
}