mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-22 23:26:39 -08:00
* feat: add comparer * refactor: rename lang with ecosystem * feat(bundler): add comparer * feat(node): add comparer * feat(bundler): integrate comparer * feat(cargo): integrate comparer * feat(composer): add comparer * feat(ghsa): integrate comparer * feat(node): integrate comparer * feat(python): integrate comparer * test(bundler): add tests * test(cargo): add tests * test(composer): add tests * test(ghsa): add tests * test(node): add tests * test(python): add tests * refactor(utils): remove unnecessary functions * test(utils): add tests * test: rename bucket prefixes * fix(detect): use string * chore: update dependencies * docs: add comments * fix(cargo): handle unpatched vulnerability * test(db): update trivy-db for integration tests * test(integration): update a golden file * test(cargo): Add a case for missing patched version Signed-off-by: Simarpreet Singh <simar@linux.com> * refactor(advisory): update comments * refactor(node/advisory): change the receiver * chore(mod): update dependencies * refactor(comparer): unexport MatchVersion * refactor: fix maligned structs * test(node): add empty value * refactor * refactor: sort imports * chore(mod): update trivy-db Co-authored-by: Simarpreet Singh <simar@linux.com>
30 lines
682 B
Go
30 lines
682 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/aquasecurity/fanal/types"
|
|
)
|
|
|
|
// FormatVersion formats the package version based on epoch, version & release
|
|
func FormatVersion(pkg types.Package) string {
|
|
return formatVersion(pkg.Epoch, pkg.Version, pkg.Release)
|
|
}
|
|
|
|
// FormatSrcVersion formats the package version based on source epoch, version & release
|
|
func FormatSrcVersion(pkg types.Package) string {
|
|
return formatVersion(pkg.SrcEpoch, pkg.SrcVersion, pkg.SrcRelease)
|
|
}
|
|
|
|
func formatVersion(epoch int, version, release string) string {
|
|
v := version
|
|
if release != "" {
|
|
v = fmt.Sprintf("%s-%s", v, release)
|
|
}
|
|
if epoch != 0 {
|
|
v = fmt.Sprintf("%d:%s", epoch, v)
|
|
}
|
|
return v
|
|
|
|
}
|