internal/license: keep license contents even if no match
Store the contents of all valid license filenames, even if they don't
match.
Fixes b/144581896.
CI-Result: Cloud Build
@@ -141,8 +141,10 @@ func detectFile(f *zip.File, prefix string) (_ *License, err error) {
}
// At this point we have a valid license candidate, and so expect a match.
- // If we don't find one, we must return an unknown license.
+ // If we don't find one, we still return all information about the license,
+ // but with an empty list of types.
filePath := strings.TrimPrefix(f.Name, prefix)
+ var types []string
cov, ok := licensecheck.Cover(contents, licensecheck.Options{})
if ok && cov.Percent >= coverageThreshold {
matchedTypes := make(map[string]bool)
@@ -151,27 +153,18 @@ func detectFile(f *zip.File, prefix string) (_ *License, err error) {
matchedTypes[m.Name] = true
}
}
- if len(matchedTypes) > 0 {
- var typs []string
for t := range matchedTypes {
- typs = append(typs, t)
- }
- sort.Strings(typs)
- return &License{
- Metadata: &Metadata{
- Types: typs,
- FilePath: filePath,
- Coverage: cov,
- },
- Contents: contents,
- }, nil
+ types = append(types, t)
}
+ sort.Strings(types)
}
return &License{
Metadata: &Metadata{
+ Types: types,
FilePath: filePath,
Coverage: cov,
},
+ Contents: contents,
}, nil
}
