pin: Do not accidentally delete indirect pins on Flush
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Tommi Virtanen committed
Jun 8, 2015 at 21:42 UTC
7a66a7dc9ffb28a6dfccf692b78968ce44235563
2 files changed
+32
pin/pin_test.go
+21
@@ -192,6 +192,27 @@ func TestDuplicateSemantics(t *testing.T) {
192
}
193
}
194
195
+func TestFlush(t *testing.T) {
196
+ dstore := dssync.MutexWrap(ds.NewMapDatastore())
197
+ bstore := blockstore.NewBlockstore(dstore)
198
+ bserv, err := bs.New(bstore, offline.Exchange(bstore))
199
+ if err != nil {
200
+ t.Fatal(err)
201
+ }
202
+
203
+ dserv := mdag.NewDAGService(bserv)
204
+ p := NewPinner(dstore, dserv)
205
+ _, k := randNode()
206
+
207
+ p.PinWithMode(k, Indirect)
208
+ if err := p.Flush(); err != nil {
209
+ t.Fatal(err)
210
+ }
211
+ if !p.IsPinned(k) {
212
+ t.Fatal("expected key to still be pinned")
213
+ }
214
+}
215
+
216
func TestPinRecursiveFail(t *testing.T) {
217
ctx := context.Background()
218
dstore := dssync.MutexWrap(ds.NewMapDatastore())
pin/set.go
+11
@@ -314,7 +314,18 @@ func storeSet(ctx context.Context, dag merkledag.DAGService, keys []key.Key, int
314
return n, nil
315
}
316
317
+func copyRefcounts(orig map[key.Key]uint64) map[key.Key]uint64 {
318
+ r := make(map[key.Key]uint64, len(orig))
319
+ for k, v := range orig {
320
+ r[k] = v
321
+ }
322
+ return r
323
+}
324
+
325
func storeMultiset(ctx context.Context, dag merkledag.DAGService, refcounts map[key.Key]uint64, internalKeys keyObserver) (*merkledag.Node, error) {
326
+ // make a working copy of the refcounts
327
+ refcounts = copyRefcounts(refcounts)
328
+
329
iter := func() (k key.Key, data []byte, ok bool) {
330
// Every call of this function returns the next refcount item.
331
//