From 2521534614c4422d865dde674c258eef9441336a Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Mon, 9 Sep 2019 15:13:31 -0400 Subject: stub out monitor --- sumdb/client.go | 73 --------------------------------------------------------- 1 file changed, 73 deletions(-) (limited to 'sumdb/client.go') diff --git a/sumdb/client.go b/sumdb/client.go index 70dd56f..e4552ae 100644 --- a/sumdb/client.go +++ b/sumdb/client.go @@ -8,7 +8,6 @@ import ( "bytes" "errors" "fmt" - "path" "strings" "sync" "sync/atomic" @@ -172,84 +171,12 @@ func (c *Client) SetTileHeight(height int) { c.tileHeight = height } -// SetGONOSUMDB sets the list of comma-separated GONOSUMDB patterns for the Client. -// For any module path matching one of the patterns, -// Lookup will return ErrGONOSUMDB. -// SetGONOSUMDB can be called at most once, -// and if so it must be called before the first call to Lookup. -func (c *Client) SetGONOSUMDB(list string) { - if atomic.LoadUint32(&c.didLookup) != 0 { - panic("SetGONOSUMDB used after Lookup") - } - if c.nosumdb != "" { - panic("multiple calls to SetGONOSUMDB") - } - c.nosumdb = list -} - -// ErrGONOSUMDB is returned by Lookup for paths that match -// a pattern listed in the GONOSUMDB list (set by SetGONOSUMDB, -// usually from the environment variable). -var ErrGONOSUMDB = errors.New("skipped (listed in GONOSUMDB)") - -func (c *Client) skip(target string) bool { - return globsMatchPath(c.nosumdb, target) -} - -// globsMatchPath reports whether any path prefix of target -// matches one of the glob patterns (as defined by path.Match) -// in the comma-separated globs list. -// It ignores any empty or malformed patterns in the list. -func globsMatchPath(globs, target string) bool { - for globs != "" { - // Extract next non-empty glob in comma-separated list. - var glob string - if i := strings.Index(globs, ","); i >= 0 { - glob, globs = globs[:i], globs[i+1:] - } else { - glob, globs = globs, "" - } - if glob == "" { - continue - } - - // A glob with N+1 path elements (N slashes) needs to be matched - // against the first N+1 path elements of target, - // which end just before the N+1'th slash. - n := strings.Count(glob, "/") - prefix := target - // Walk target, counting slashes, truncating at the N+1'th slash. - for i := 0; i < len(target); i++ { - if target[i] == '/' { - if n == 0 { - prefix = target[:i] - break - } - n-- - } - } - if n > 0 { - // Not enough prefix elements. - continue - } - matched, _ := path.Match(glob, prefix) - if matched { - return true - } - } - return false -} - // Lookup returns the go.sum lines for the given module path and version. // The version may end in a /go.mod suffix, in which case Lookup returns // the go.sum lines for the module's go.mod-only hash. func (c *Client) Lookup(path, vers string) (lines []string, err error) { atomic.StoreUint32(&c.didLookup, 1) - if c.skip(path) { - return nil, ErrGONOSUMDB - } - defer func() { if err != nil { err = fmt.Errorf("%s@%s: %v", path, vers, err) -- cgit v1.2.3