feat: improve dpkg cataloger license recognition for "license agreements" (#3888)

This commit is contained in:
Christopher Angelo Phillips
2025-05-14 08:41:48 -04:00
committed by GitHub
parent 175a6719a9
commit e5d7760bb8
6 changed files with 207 additions and 13 deletions
+9 -2
View File
@@ -118,17 +118,24 @@ func addLicenses(ctx context.Context, resolver file.Resolver, dbLocation file.Lo
// get license information from the copyright file
copyrightReader, copyrightLocation := fetchCopyrightContents(resolver, dbLocation, metadata)
var licenseStrs []string
if copyrightReader != nil && copyrightLocation != nil {
defer internal.CloseAndLogError(copyrightReader, copyrightLocation.AccessPath)
// attach the licenses
licenseStrs := parseLicensesFromCopyright(copyrightReader)
licenseStrs = parseLicensesFromCopyright(copyrightReader)
for _, licenseStr := range licenseStrs {
p.Licenses.Add(pkg.NewLicenseFromLocationsWithContext(ctx, licenseStr, copyrightLocation.WithoutAnnotations()))
}
// keep a record of the file where this was discovered
p.Locations.Add(*copyrightLocation)
}
// try to use the license classifier if parsing the copyright file failed
if len(licenseStrs) == 0 {
sr, sl := fetchCopyrightContents(resolver, dbLocation, metadata)
if sr != nil && sl != nil {
p.Licenses.Add(pkg.NewLicensesFromReadCloserWithContext(ctx, file.NewLocationReadCloser(*sl, sr))...)
}
}
}
func mergeFileListing(resolver file.Resolver, dbLocation file.Location, p *pkg.Package) {