Skip to content

Commit

Permalink
sumdb: replace globsMatchPath with module.MatchPrefixPatterns
Browse files Browse the repository at this point in the history
In CL 239797, src/cmd/go/internal/str.GlobsMatchPath was replicated as
module.MatchPrefixPatterns. This redundancy eliminates the need for
globsMatchPath. This CL replaces calls to globsMatchPath with
module.MatchPrefixPatterns and removes the now redundant globsMatchPath.

Change-Id: Idd6fc10e7cf24d7b9603fa17edb2460d50b2e4aa
Reviewed-on: https://go-review.googlesource.com/c/mod/+/539815
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
aofei authored and gopherbot committed Jan 26, 2024
1 parent 6e58e47 commit fa1ba42
Showing 1 changed file with 1 addition and 46 deletions.
47 changes: 1 addition & 46 deletions sumdb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"errors"
"fmt"
"path"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -193,51 +192,7 @@ func (c *Client) SetGONOSUMDB(list string) {
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
return module.MatchPrefixPatterns(c.nosumdb, target)
}

// Lookup returns the go.sum lines for the given module path and version.
Expand Down

0 comments on commit fa1ba42

Please sign in to comment.