Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dont use searchset for indirect pin checking
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
whyrusleeping committed Jul 10, 2015
1 parent c2fc8bc commit 1bb4530
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions pin/pin.go
Original file line number Diff line number Diff line change
@@ -177,19 +177,16 @@ func (p *pinner) isPinned(k key.Key) (string, bool, error) {
}

for _, rk := range p.recursePin.GetKeys() {
ss := &searchSet{target: k}

rnd, err := p.dserv.Get(context.Background(), rk)
if err != nil {
return "", false, err
}

err = mdag.EnumerateChildren(context.Background(), p.dserv, rnd, ss)
has, err := hasChild(p.dserv, rnd, k)
if err != nil {
return "", false, err
}

if ss.found {
if has {
return rk.B58String(), true, nil
}
}
@@ -350,26 +347,19 @@ func (p *pinner) PinWithMode(k key.Key, mode PinMode) {
}
}

// searchSet implements key.KeySet in
type searchSet struct {
target key.Key
found bool
}

func (ss *searchSet) Add(k key.Key) {
if ss.target == k {
ss.found = true
}
}
func hasChild(ds mdag.DAGService, root *mdag.Node, child key.Key) (bool, error) {
for _, lnk := range root.Links {
k := key.Key(lnk.Hash)
if k == child {
return true, nil
}

func (ss *searchSet) Has(k key.Key) bool {
// returning true to all Has queries will cause EnumerateChildren to return
// almost immediately
return ss.found
}
nd, err := ds.Get(context.Background(), k)
if err != nil {
return false, err
}

func (ss *searchSet) Keys() []key.Key {
return nil
return hasChild(ds, nd, child)
}
return false, nil
}

func (ss *searchSet) Remove(key.Key) {}

0 comments on commit 1bb4530

Please sign in to comment.