1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-09 23:42:20 +08:00

pin: Do not accidentally delete indirect pins on Flush

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Tommi Virtanen
2015-06-08 21:42:04 -07:00
committed by Jeromy
parent 896601f6cb
commit 7a66a7dc9f
2 changed files with 32 additions and 0 deletions

View File

@ -192,6 +192,27 @@ func TestDuplicateSemantics(t *testing.T) {
}
}
func TestFlush(t *testing.T) {
dstore := dssync.MutexWrap(ds.NewMapDatastore())
bstore := blockstore.NewBlockstore(dstore)
bserv, err := bs.New(bstore, offline.Exchange(bstore))
if err != nil {
t.Fatal(err)
}
dserv := mdag.NewDAGService(bserv)
p := NewPinner(dstore, dserv)
_, k := randNode()
p.PinWithMode(k, Indirect)
if err := p.Flush(); err != nil {
t.Fatal(err)
}
if !p.IsPinned(k) {
t.Fatal("expected key to still be pinned")
}
}
func TestPinRecursiveFail(t *testing.T) {
ctx := context.Background()
dstore := dssync.MutexWrap(ds.NewMapDatastore())

View File

@ -314,7 +314,18 @@ func storeSet(ctx context.Context, dag merkledag.DAGService, keys []key.Key, int
return n, nil
}
func copyRefcounts(orig map[key.Key]uint64) map[key.Key]uint64 {
r := make(map[key.Key]uint64, len(orig))
for k, v := range orig {
r[k] = v
}
return r
}
func storeMultiset(ctx context.Context, dag merkledag.DAGService, refcounts map[key.Key]uint64, internalKeys keyObserver) (*merkledag.Node, error) {
// make a working copy of the refcounts
refcounts = copyRefcounts(refcounts)
iter := func() (k key.Key, data []byte, ok bool) {
// Every call of this function returns the next refcount item.
//