mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 15:36:41 +01:00
--------- Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com> Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package arch
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/anchore/packageurl-go"
|
|
"github.com/anchore/syft/syft/file"
|
|
"github.com/anchore/syft/syft/linux"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
)
|
|
|
|
func newPackage(ctx context.Context, m *parsedData, release *linux.Release, dbLocation file.Location, otherLocations ...file.Location) pkg.Package {
|
|
licenseCandidates := strings.Split(m.Licenses, "\n")
|
|
|
|
locs := file.NewLocationSet(dbLocation)
|
|
locs.Add(otherLocations...)
|
|
|
|
p := pkg.Package{
|
|
Name: m.Package,
|
|
Version: m.Version,
|
|
Locations: locs,
|
|
Licenses: pkg.NewLicenseSet(pkg.NewLicensesFromLocationWithContext(ctx, dbLocation.WithoutAnnotations(), licenseCandidates...)...),
|
|
Type: pkg.AlpmPkg,
|
|
PURL: packageURL(m, release),
|
|
Metadata: m.AlpmDBEntry,
|
|
}
|
|
p.SetID()
|
|
|
|
return p
|
|
}
|
|
|
|
func packageURL(m *parsedData, distro *linux.Release) string {
|
|
if distro == nil || distro.ID != "arch" {
|
|
// note: there is no namespace variation (like with debian ID_LIKE for ubuntu ID, for example)
|
|
return ""
|
|
}
|
|
|
|
qualifiers := map[string]string{
|
|
pkg.PURLQualifierArch: m.Architecture,
|
|
}
|
|
|
|
if m.BasePackage != "" {
|
|
qualifiers[pkg.PURLQualifierUpstream] = m.BasePackage
|
|
}
|
|
|
|
return packageurl.NewPackageURL(
|
|
"alpm", // `alpm` for Arch Linux and other users of the libalpm/pacman package manager. (see https://github.com/package-url/purl-spec/pull/164)
|
|
distro.ID,
|
|
m.Package,
|
|
m.Version,
|
|
pkg.PURLQualifiers(
|
|
qualifiers,
|
|
distro,
|
|
),
|
|
"",
|
|
).ToString()
|
|
}
|