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" {
nvr = realNvr
}
break
} else {
if nvr != rpmObj.SourceRPM() && nvr != fmt.Sprintf("%s.rpm", realNvr) {
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)
}
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])
beginTx, err := c.db.Begin()

View File

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

View File

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