mirror of
https://github.com/anchore/syft.git
synced 2026-11-05 00:46:38 +01:00
Use case-insensitive matching for Go license files (#2286)
Signed-off-by: Mark Severson <mark@kasten.io>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user