1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-09 19:32:24 +08:00
Files
kubo/pin/indirect.go
Tommi Virtanen e5b8ee4819 pin: Rewrite to store pins in IPFS objects
WARNING: No migration performed! That needs to come in a separate
commit, perhaps amended into this one.

This is the minimal rewrite, only changing the storage from
JSON(+extra keys) in Datastore to IPFS objects. All of the pinning
state is still loaded in memory, and written from scratch on Flush. To
do more would require API changes, e.g. adding error returns.

Set/Multiset is not cleanly separated into a library, yet, as it's API
is expected to change radically.

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
2016-01-12 08:21:13 -08:00

40 lines
705 B
Go

package pin
import (
key "github.com/ipfs/go-ipfs/blocks/key"
)
type indirectPin struct {
refCounts map[key.Key]uint64
}
func newIndirectPin() *indirectPin {
return &indirectPin{
refCounts: make(map[key.Key]uint64),
}
}
func (i *indirectPin) Increment(k key.Key) {
i.refCounts[k]++
}
func (i *indirectPin) Decrement(k key.Key) {
if i.refCounts[k] == 0 {
log.Warningf("pinning: bad call: asked to unpin nonexistent indirect key: %v", k)
return
}
i.refCounts[k]--
if i.refCounts[k] == 0 {
delete(i.refCounts, k)
}
}
func (i *indirectPin) HasKey(k key.Key) bool {
_, found := i.refCounts[k]
return found
}
func (i *indirectPin) GetRefs() map[key.Key]uint64 {
return i.refCounts
}