Add support for unusual NVRs to yumrepofs

Signed-off-by: Mustafa Gezen <mustafa@ctrliq.com>
This commit is contained in:
Mustafa Gezen 2022-08-25 03:32:59 +02:00
parent d3e5d9ea92
commit 6848798e1b
Signed by untrusted user who does not match committer: mustafa
GPG Key ID: DCDF010D946438C1
3 changed files with 30 additions and 11 deletions

View File

@ -357,6 +357,8 @@ func (c *Controller) RpmImportActivity(ctx context.Context, req *peridotpb.RpmIm
if nvr == "" && rpmObj.Architecture() == "i686" { if nvr == "" && rpmObj.Architecture() == "i686" {
nvr = realNvr nvr = realNvr
} }
break
} else { } else {
if nvr != rpmObj.SourceRPM() && nvr != fmt.Sprintf("%s.rpm", realNvr) { if nvr != rpmObj.SourceRPM() && nvr != fmt.Sprintf("%s.rpm", realNvr) {
return nil, fmt.Errorf("only include RPMs from one package") return nil, fmt.Errorf("only include RPMs from one package")
@ -367,7 +369,12 @@ func (c *Controller) RpmImportActivity(ctx context.Context, req *peridotpb.RpmIm
return nil, fmt.Errorf("invalid SNVR: %s", nvr) return nil, fmt.Errorf("invalid SNVR: %s", nvr)
} }
nvrMatch := rpmutils.NVR().FindStringSubmatch(nvr) var nvrMatch []string
if rpmutils.NVRUnusualRelease().MatchString(nvr) {
nvrMatch = rpmutils.NVRUnusualRelease().FindStringSubmatch(nvr)
} else {
nvrMatch = rpmutils.NVR().FindStringSubmatch(nvr)
}
srcNvra := fmt.Sprintf("%s-%s-%s.src", nvrMatch[1], nvrMatch[2], nvrMatch[3]) srcNvra := fmt.Sprintf("%s-%s-%s.src", nvrMatch[1], nvrMatch[2], nvrMatch[3])
beginTx, err := c.db.Begin() beginTx, err := c.db.Begin()

View File

@ -227,8 +227,13 @@ func GenerateArchMapForArtifacts(artifacts models.TaskArtifacts, project *models
for i, artifact := range artifacts { for i, artifact := range artifacts {
var name string var name string
var arch string var arch string
if rpmutils.NVR().MatchString(filepath.Base(artifact.Name)) { base := strings.TrimSuffix(filepath.Base(artifact.Name), ".rpm")
nvr := rpmutils.NVR().FindStringSubmatch(filepath.Base(artifact.Name)) if rpmutils.NVRUnusualRelease().MatchString(base) {
nvr := rpmutils.NVRUnusualRelease().FindStringSubmatch(base)
name = nvr[1]
arch = nvr[4]
} else if rpmutils.NVR().MatchString(base) {
nvr := rpmutils.NVR().FindStringSubmatch(base)
name = nvr[1] name = nvr[1]
arch = nvr[4] arch = nvr[4]
} }
@ -324,7 +329,6 @@ func GenerateArchMapForArtifacts(artifacts models.TaskArtifacts, project *models
artifactArchMap[arch] = append(artifactArchMap[arch], &newArtifact) artifactArchMap[arch] = append(artifactArchMap[arch], &newArtifact)
} }
} else { } else {
arch := artifact.Arch
if composetools.IsDebugPackage(name) { if composetools.IsDebugPackage(name) {
arch = arch + "-debug" arch = arch + "-debug"
} }

View File

@ -33,13 +33,14 @@ package rpmutils
import "regexp" import "regexp"
var ( var (
nvr *regexp.Regexp nvr *regexp.Regexp
nvrNoArch *regexp.Regexp nvrNoArch *regexp.Regexp
epoch *regexp.Regexp nvrUnusualRelease *regexp.Regexp
module *regexp.Regexp epoch *regexp.Regexp
dist *regexp.Regexp module *regexp.Regexp
moduleDist *regexp.Regexp dist *regexp.Regexp
advisoryId *regexp.Regexp moduleDist *regexp.Regexp
advisoryId *regexp.Regexp
) )
func NVR() *regexp.Regexp { func NVR() *regexp.Regexp {
@ -56,6 +57,13 @@ func NVRNoArch() *regexp.Regexp {
return nvrNoArch return nvrNoArch
} }
func NVRUnusualRelease() *regexp.Regexp {
if nvrUnusualRelease == nil {
nvrUnusualRelease = regexp.MustCompile("^(\\S+)-([\\w~%.+]+)-(\\w+?)(?:\\.(\\w+))?(?:\\.rpm)?$")
}
return nvrUnusualRelease
}
func Epoch() *regexp.Regexp { func Epoch() *regexp.Regexp {
if epoch == nil { if epoch == nil {
epoch = regexp.MustCompile("(\\d+):") epoch = regexp.MustCompile("(\\d+):")