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

Correct pinning for dagmodifier, and a bunch more tests

This commit is contained in:
Jeromy
2015-03-10 12:57:29 -07:00
parent 5ead2a9fab
commit 50f0b06bdf
5 changed files with 271 additions and 36 deletions

View File

@ -47,6 +47,7 @@ type Pinner interface {
// may not be successful
type ManualPinner interface {
PinWithMode(util.Key, PinMode)
RemovePinWithMode(util.Key, PinMode)
Pinner
}
@ -198,6 +199,20 @@ func (p *pinner) IsPinned(key util.Key) bool {
p.indirPin.HasKey(key)
}
func (p *pinner) RemovePinWithMode(key util.Key, mode PinMode) {
switch mode {
case Direct:
p.directPin.RemoveBlock(key)
case Indirect:
p.indirPin.Decrement(key)
case Recursive:
p.recursePin.RemoveBlock(key)
default:
// programmer error, panic OK
panic("unrecognized pin type")
}
}
// LoadPinner loads a pinner and its keysets from the given datastore
func LoadPinner(d ds.ThreadSafeDatastore, dserv mdag.DAGService) (Pinner, error) {
p := new(pinner)