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.

Change-Id: If4620d67525291eef2de2a81dc5875046b1d3dbb
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/603790
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Jonathan Amsterdam 2019-11-21 09:40:25 -05:00 коммит произвёл Julie Qiu
Родитель 4e25618631
Коммит cfef41cecc
1 изменённых файлов: 8 добавлений и 15 удалений

Просмотреть файл

@ -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
for t := range matchedTypes {
types = append(types, t)
}
sort.Strings(types)
}
return &License{
Metadata: &Metadata{
Types: types,
FilePath: filePath,
Coverage: cov,
},
Contents: contents,
}, nil
}