Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions updater/fetchers/rocky/rocky.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,25 @@ func productNameToNamespace(productName string) string {
// NEVRA format: name-[epoch:]version-release.arch.rpm
// Example with epoch:
//
// "valkey-0:8.0.6-2.el10_1.ppc64le.rpm" -> "8.0.6-2.el10_1"
func extractVersionFromNevra(nvraString string) string {
lastPeriod := strings.LastIndex(nvraString, ".")
nvraString = nvraString[:lastPeriod]
lastPeriod = strings.LastIndex(nvraString, ".")
nvraString = nvraString[:lastPeriod]
//Get module name from section before epoch
epochIndex := strings.Index(nvraString, ":")

//Remaining section is version
moduleVersion := nvraString[epochIndex-1:]
return moduleVersion
// "valkey-0:8.0.6-2.el10_1.ppc64le.rpm" -> "valkey", "8.0.6-2.el10_1"
func extractVersionModuleFromNevra(nevra string) (string, string) {

nevra = strings.TrimSuffix(nevra, ".rpm")

if lastPeriod := strings.LastIndex(nevra, "."); lastPeriod > 0 {
nevra = nevra[:lastPeriod]
}

nevraInfo := strings.Split(nevra, ":")
if len(nevraInfo) != 2 {
return "", ""
}
moduleName := nevraInfo[0]
if lastPeriod := strings.LastIndex(moduleName, "-"); lastPeriod > 0 {
moduleName = moduleName[:lastPeriod]
}
moduleVersion := nevraInfo[1]
return moduleName, moduleVersion
}

// buildFixedInByNamespace organizes fixed package versions by Rocky Linux product namespace.
Expand Down Expand Up @@ -174,7 +181,7 @@ func buildFixedInByNamespace(affectedProducts []affectedProduct, packages []pkg)
groupPakcage = packagesByNamespace[affectedProductNamespace]
}

pkgVersion := extractVersionFromNevra(pkg.Nevra)
pkgName, pkgVersion := extractVersionModuleFromNevra(pkg.Nevra)
if _, existing := groupPakcage[pkgVersion]; !existing {
fvVer, err := common.NewVersion(pkgVersion)
if err != nil {
Expand All @@ -183,7 +190,7 @@ func buildFixedInByNamespace(affectedProducts []affectedProduct, packages []pkg)

groupPakcage[pkgVersion] = common.FeatureVersion{
Feature: common.Feature{
Name: pkg.PackageName,
Name: pkgName,
Namespace: affectedProductNamespace,
},
Version: fvVer,
Expand Down
25 changes: 25 additions & 0 deletions updater/fetchers/rocky/rocky_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package rocky

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestExtractVersionModuleFromNevra(t *testing.T) {
tests := []struct {
nevra string
moduleName string
moduleVersion string
}{
{nevra: "valkey-0:8.0.6-2.el10_1.ppc64le.rpm", moduleName: "valkey", moduleVersion: "8.0.6-2.el10_1"},
{nevra: "kernel-0:6.12.0-124.8.1.el10_1.aarch64.rpm", moduleName: "kernel", moduleVersion: "6.12.0-124.8.1.el10_1"},
{nevra: "kernel-64k-debug-core-0:6.12.0-124.8.1.el10_1.aarch64.rpm", moduleName: "kernel-64k-debug-core", moduleVersion: "6.12.0-124.8.1.el10_1"},
{nevra: "kernel-abi-stablelists-0:6.12.0-124.8.1.el10_1.noarch.rpm", moduleName: "kernel-abi-stablelists", moduleVersion: "6.12.0-124.8.1.el10_1"},
}
for _, test := range tests {
moduleName, moduleVersion := extractVersionModuleFromNevra(test.nevra)
require.Equal(t, test.moduleName, moduleName)
require.Equal(t, test.moduleVersion, moduleVersion)
}
}