Use case-insensitive matching for Go license files (#2286)

Signed-off-by: Mark Severson <mark@kasten.io>
This commit is contained in:
Mark Severson
2023-11-03 14:47:09 -04:00
committed by GitHub
parent 2d582f78a1
commit 1470abaded
3 changed files with 223 additions and 3 deletions
+11 -3
View File
@@ -32,7 +32,7 @@ type goLicenses struct {
opts GoCatalogerOpts
localModCacheResolver file.WritableResolver
progress *monitor.CatalogerTask
licenseFileNames *strset.Set
lowerLicenseFileNames *strset.Set
}
func newGoLicenses(opts GoCatalogerOpts) goLicenses {
@@ -44,10 +44,18 @@ func newGoLicenses(opts GoCatalogerOpts) goLicenses {
RemoveOnCompletion: true,
Title: "Downloading go mod",
},
licenseFileNames: strset.New(licenses.FileNames()...),
lowerLicenseFileNames: strset.New(lowercaseLicenseFiles()...),
}
}
func lowercaseLicenseFiles() []string {
fileNames := licenses.FileNames()
for i := range fileNames {
fileNames[i] = strings.ToLower(fileNames[i])
}
return fileNames
}
func remotesForModule(proxies []string, noProxy []string, module string) []string {
for _, pattern := range noProxy {
if matched, err := path.Match(pattern, module); err == nil && matched {
@@ -158,7 +166,7 @@ func (c *goLicenses) findLicenses(resolver file.Resolver, globMatch string) (out
for _, l := range locations {
fileName := path.Base(l.RealPath)
if c.licenseFileNames.Has(fileName) {
if c.lowerLicenseFileNames.Has(strings.ToLower(fileName)) {
contents, err := resolver.FileContentsByLocation(l)
if err != nil {
return nil, err