Skip to content

Commit 58627b6

Browse files
authored
Added support for second package condition/version argument in conver… (#654)
* Added support for second package condition/version argument in convertPackageVersionToTdnfArg function. * fixed syntax * Added back the original comments on the removal of ">" and ">=" constraints.
1 parent 4ab0d51 commit 58627b6

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

toolkit/tools/internal/packagerepo/repocloner/rpmrepocloner/rpmrepocloner.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,25 +674,61 @@ func convertPackageVersionToTdnfArg(pkgVer *pkgjson.PackageVer) (tdnfArg string)
674674

675675
// TDNF does not accept versioning information on implicit provides.
676676
if pkgVer.IsImplicitPackage() {
677-
if pkgVer.Condition != "" {
677+
if pkgVer.Condition != "" || pkgVer.SCondition != "" {
678678
logger.Log.Warnf("Discarding version constraint for implicit package: %v", pkgVer)
679679
}
680680
return
681681
}
682682

683+
// Handle first condition
684+
var firstConstraint, secondConstraint string
685+
686+
683687
// To avoid significant overhead we only download the latest version of a package
684688
// for ">" and ">=" constraints (ie remove constraints).
689+
685690
switch pkgVer.Condition {
686691
case "":
687692
case "=":
688-
tdnfArg = fmt.Sprintf("%s-%s", pkgVer.Name, pkgVer.Version)
693+
firstConstraint = fmt.Sprintf("%s-%s", pkgVer.Name, pkgVer.Version)
694+
tdnfArg = firstConstraint // For exact matches, use this format
695+
return // Don't process second condition for exact matches
696+
case "<=", "<":
697+
firstConstraint = fmt.Sprintf("%s %s %s", pkgVer.Name, pkgVer.Condition, pkgVer.Version)
698+
case ">", ">=":
699+
logger.Log.Warnf("Discarding '%s' version constraint for performance: %v", pkgVer.Condition, pkgVer)
700+
// Don't set firstConstraint, we're discarding this
701+
default:
702+
if pkgVer.Condition != "" {
703+
logger.Log.Errorf("Unsupported version constraint: %s", pkgVer.Condition)
704+
}
705+
}
706+
707+
// Handle second condition
708+
switch pkgVer.SCondition {
709+
case "":
710+
case "=":
711+
secondConstraint = fmt.Sprintf("%s-%s", pkgVer.Name, pkgVer.SVersion)
689712
case "<=", "<":
690-
tdnfArg = fmt.Sprintf("%s %s %s", pkgVer.Name, pkgVer.Condition, pkgVer.Version)
713+
secondConstraint = fmt.Sprintf("%s %s %s", pkgVer.Name, pkgVer.SCondition, pkgVer.SVersion)
691714
case ">", ">=":
692-
logger.Log.Warnf("Discarding '%s' version constraint for: %v", pkgVer.Condition, pkgVer)
715+
logger.Log.Warnf("Discarding '%s' second version constraint for performance: %v", pkgVer.SCondition, pkgVer)
716+
// Don't set secondConstraint, we're discarding this
693717
default:
694-
logger.Log.Errorf("Unsupported version constraint: %s", pkgVer.Condition)
718+
if pkgVer.SCondition != "" {
719+
logger.Log.Errorf("Unsupported second version constraint: %s", pkgVer.SCondition)
720+
}
721+
}
722+
723+
// Combine constraints
724+
if firstConstraint != "" && secondConstraint != "" {
725+
tdnfArg = fmt.Sprintf("%s %s", firstConstraint, secondConstraint)
726+
} else if firstConstraint != "" {
727+
tdnfArg = firstConstraint
728+
} else if secondConstraint != "" {
729+
tdnfArg = secondConstraint
695730
}
731+
// else tdnfArg remains just the package name
696732

697733
return
698734
}

0 commit comments

Comments
 (0)