Skip to content

Commit

Permalink
notary/internal/sumweb: extract hasGlobsPathPrefix from glob-matching
Browse files Browse the repository at this point in the history
It will be necessary for GONOPROXY in the go command.
Having a separate function will make it easier to share the code.
(When the code moves into the go command, this function
will probably move to a different package.)

Change-Id: Idac79a40a144068b4cdf9f52f15c66d46f0f2908
Reviewed-on: https://go-review.googlesource.com/c/exp/+/173540
Run-TryBot: Russ Cox <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Filippo Valsorda <[email protected]>
  • Loading branch information
rsc committed Apr 26, 2019
1 parent 79ac8e8 commit 2cc83dd
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions notary/internal/sumweb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type Conn struct {
verifiers note.Verifiers // accepted verifiers (just one, but Verifiers for note.Open)
tileReader tileReader
tileHeight int
noverify []string
nosumdb string

record parCache // cache of record lookup, keyed by path@vers
tileCache parCache // cache of tile from client.ReadCache, keyed by tile
Expand Down Expand Up @@ -166,12 +166,7 @@ func (c *Conn) SetTileHeight(height int) {
// Lookup will return ErrGONOSUMDB.
// Any call to SetGONOSUMDB must happen before the first call to Lookup.
func (c *Conn) SetGONOSUMDB(list string) {
c.noverify = nil
for _, glob := range strings.Split(list, ",") {
if glob != "" {
c.noverify = append(c.noverify, glob)
}
}
c.nosumdb = list
}

// ErrGONOSUMDB is returned by Lookup for paths that match
Expand All @@ -180,7 +175,26 @@ func (c *Conn) SetGONOSUMDB(list string) {
var ErrGONOSUMDB = errors.New("skipped (listed in GONOSUMDB)")

func (c *Conn) skip(target string) bool {
for _, glob := range c.noverify {
return hasGlobsPathPrefix(c.nosumdb, target)
}

// hasGlobsPathPrefix 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 hasGlobsPathPrefix(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.
Expand Down

0 comments on commit 2cc83dd

Please sign in to comment.