From fa1ba4269bda724bb9f01ec381fbbaf031e45833 Mon Sep 17 00:00:00 2001 From: Aofei Sheng Date: Sat, 4 Nov 2023 19:02:03 +0800 Subject: [PATCH] sumdb: replace globsMatchPath with module.MatchPrefixPatterns 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 Reviewed-by: Cherry Mui Reviewed-by: Bryan Mills LUCI-TryBot-Result: Go LUCI --- sumdb/client.go | 47 +---------------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/sumdb/client.go b/sumdb/client.go index aecdc68..04c6e24 100644 --- a/sumdb/client.go +++ b/sumdb/client.go @@ -8,7 +8,6 @@ import ( "bytes" "errors" "fmt" - "path" "strings" "sync" "sync/atomic" @@ -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.