Skip to content

Commit fa1ba42

Browse files
aofeigopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 6e58e47 commit fa1ba42

File tree

1 file changed

+1
-46
lines changed

1 file changed

+1
-46
lines changed

sumdb/client.go

+1-46
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"bytes"
99
"errors"
1010
"fmt"
11-
"path"
1211
"strings"
1312
"sync"
1413
"sync/atomic"
@@ -193,51 +192,7 @@ func (c *Client) SetGONOSUMDB(list string) {
193192
var ErrGONOSUMDB = errors.New("skipped (listed in GONOSUMDB)")
194193

195194
func (c *Client) skip(target string) bool {
196-
return globsMatchPath(c.nosumdb, target)
197-
}
198-
199-
// globsMatchPath reports whether any path prefix of target
200-
// matches one of the glob patterns (as defined by path.Match)
201-
// in the comma-separated globs list.
202-
// It ignores any empty or malformed patterns in the list.
203-
func globsMatchPath(globs, target string) bool {
204-
for globs != "" {
205-
// Extract next non-empty glob in comma-separated list.
206-
var glob string
207-
if i := strings.Index(globs, ","); i >= 0 {
208-
glob, globs = globs[:i], globs[i+1:]
209-
} else {
210-
glob, globs = globs, ""
211-
}
212-
if glob == "" {
213-
continue
214-
}
215-
216-
// A glob with N+1 path elements (N slashes) needs to be matched
217-
// against the first N+1 path elements of target,
218-
// which end just before the N+1'th slash.
219-
n := strings.Count(glob, "/")
220-
prefix := target
221-
// Walk target, counting slashes, truncating at the N+1'th slash.
222-
for i := 0; i < len(target); i++ {
223-
if target[i] == '/' {
224-
if n == 0 {
225-
prefix = target[:i]
226-
break
227-
}
228-
n--
229-
}
230-
}
231-
if n > 0 {
232-
// Not enough prefix elements.
233-
continue
234-
}
235-
matched, _ := path.Match(glob, prefix)
236-
if matched {
237-
return true
238-
}
239-
}
240-
return false
195+
return module.MatchPrefixPatterns(c.nosumdb, target)
241196
}
242197

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

0 commit comments

Comments
 (0)