// Pin the given node, optionally recursive func (p *pinner) Pin(ctx context.Context, node node.Node, recurse bool) error { p.lock.Lock() defer p.lock.Unlock() c := node.Cid() if recurse { if p.recursePin.Has(c) { return nil } if p.directPin.Has(c) { p.directPin.Remove(c) } // fetch entire graph err := mdag.FetchGraph(ctx, c, p.dserv) if err != nil { return err } p.recursePin.Add(c) } else { if _, err := p.dserv.Get(ctx, c); err != nil { return err } if p.recursePin.Has(c) { return fmt.Errorf("%s already pinned recursively", c.String()) } p.directPin.Add(c) } return nil }
// Pin the given node, optionally recursive func (p *pinner) Pin(ctx context.Context, node *mdag.Node, recurse bool) error { p.lock.Lock() defer p.lock.Unlock() k, err := node.Key() if err != nil { return err } if recurse { if p.recursePin.HasKey(k) { return nil } if p.directPin.HasKey(k) { p.directPin.RemoveBlock(k) } // fetch entire graph err := mdag.FetchGraph(ctx, node, p.dserv) if err != nil { return err } p.recursePin.AddBlock(k) } else { if _, err := p.dserv.Get(ctx, k); err != nil { return err } if p.recursePin.HasKey(k) { return fmt.Errorf("%s already pinned recursively", k.B58String()) } p.directPin.AddBlock(k) } return nil }