docs for pin method impls
License: MIT Signed-off-by: ForrestWeston <forrest@protocol.ai>
ForrestWeston committed
Jan 22, 2018 at 14:52 UTC
83ccc7e44bb1e0cb20f788c47ecf3fd80abd2b26
1 file changed
+14
pin/pin.go
+14
@@ -147,6 +147,7 @@ type Pinned struct {
147
Via *cid.Cid
148
}
149
150
+// Pinned returns whether or not the given cid is pinned
151
func (p Pinned) Pinned() bool {
152
if p.Mode == NotPinned {
153
return false
@@ -155,6 +156,7 @@ func (p Pinned) Pinned() bool {
156
}
157
}
158
159
+// String Returns pin status as string
160
func (p Pinned) String() string {
161
switch p.Mode {
162
case NotPinned:
@@ -277,6 +279,8 @@ func (p *pinner) IsPinned(c *cid.Cid) (string, bool, error) {
279
return p.isPinnedWithType(c, Any)
280
}
281
282
+// IsPinnedWithType returns whether or not the given cid is pinned with the
283
+// given pin type, as well as returning the type of pin its pinned with.
284
func (p *pinner) IsPinnedWithType(c *cid.Cid, mode PinMode) (string, bool, error) {
285
p.lock.RLock()
286
defer p.lock.RUnlock()
@@ -328,6 +332,8 @@ func (p *pinner) isPinnedWithType(c *cid.Cid, mode PinMode) (string, bool, error
332
return "", false, nil
333
}
334
335
+// CheckIfPinned Checks if a set of keys are pinned, more efficient than
336
+// calling IsPinned for each key, returns the pinned status of cid(s)
337
func (p *pinner) CheckIfPinned(cids ...*cid.Cid) ([]Pinned, error) {
338
p.lock.RLock()
339
defer p.lock.RUnlock()
@@ -393,6 +399,9 @@ func (p *pinner) CheckIfPinned(cids ...*cid.Cid) ([]Pinned, error) {
399
return pinned, nil
400
}
401
402
+// RemovePinWithMode is for manually editing the pin structure.
403
+// Use with care! If used improperly, garbage collection may not
404
+// be successful.
405
func (p *pinner) RemovePinWithMode(c *cid.Cid, mode PinMode) {
406
p.lock.Lock()
407
defer p.lock.Unlock()
@@ -486,6 +495,9 @@ func (p *pinner) RecursiveKeys() []*cid.Cid {
495
return p.recursePin.Keys()
496
}
497
498
+// Update updates a recursive pin from one cid to another
499
+// this is more efficient than simply pinning the new one and unpinning the
500
+// old one
501
func (p *pinner) Update(ctx context.Context, from, to *cid.Cid, unpin bool) error {
502
p.lock.Lock()
503
defer p.lock.Unlock()
@@ -556,6 +568,8 @@ func (p *pinner) Flush() error {
568
return nil
569
}
570
571
+// InternalPins returns all cids kept pinned for the internal state of the
572
+// pinner
573
func (p *pinner) InternalPins() []*cid.Cid {
574
p.lock.Lock()
575
defer p.lock.Unlock()