mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 14:34:24 +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:
@ -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) {
|
func TestPinRecursiveFail(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
dstore := dssync.MutexWrap(ds.NewMapDatastore())
|
dstore := dssync.MutexWrap(ds.NewMapDatastore())
|
||||||
|
11
pin/set.go
11
pin/set.go
@ -314,7 +314,18 @@ func storeSet(ctx context.Context, dag merkledag.DAGService, keys []key.Key, int
|
|||||||
return n, nil
|
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) {
|
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) {
|
iter := func() (k key.Key, data []byte, ok bool) {
|
||||||
// Every call of this function returns the next refcount item.
|
// Every call of this function returns the next refcount item.
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user