diff --git a/cmd/build.go b/cmd/build.go index d63cde63..29f4a81c 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -106,8 +106,12 @@ var buildCmd = &cobra.Command{ } pack := &pkg.DefaultPackage{ - Name: gp.Name, - Version: fmt.Sprintf("%s%s%s", gp.Condition.String(), gp.Version, gp.VersionSuffix), + Name: gp.Name, + Version: fmt.Sprintf("%s%s%s", + pkg.PkgSelectorConditionFromInt(gp.Condition.Int()).String(), + gp.Version, + gp.VersionSuffix, + ), Category: gp.Category, Uri: make([]string, 0), } diff --git a/cmd/install.go b/cmd/install.go index 75190eb2..bc9b1ec8 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -48,18 +48,18 @@ var installCmd = &cobra.Command{ Fatal("Invalid package string ", a, ": ", err.Error()) } - cond := gp.Condition.String() - if cond == "=" { - cond = "" - } if gp.Version == "" { gp.Version = "0" gp.Condition = _gentoo.PkgCondGreaterEqual } pack := &pkg.DefaultPackage{ - Name: gp.Name, - Version: fmt.Sprintf("%s%s%s", cond, gp.Version, gp.VersionSuffix), + Name: gp.Name, + Version: fmt.Sprintf("%s%s%s", + pkg.PkgSelectorConditionFromInt(gp.Condition.Int()).String(), + gp.Version, + gp.VersionSuffix, + ), Category: gp.Category, Uri: make([]string, 0), } diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 3599210d..fef127ca 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -50,8 +50,12 @@ var uninstallCmd = &cobra.Command{ } pack := &pkg.DefaultPackage{ - Name: gp.Name, - Version: fmt.Sprintf("%s%s%s", gp.Condition.String(), gp.Version, gp.VersionSuffix), + Name: gp.Name, + Version: fmt.Sprintf("%s%s%s", + pkg.PkgSelectorConditionFromInt(gp.Condition.Int()).String(), + gp.Version, + gp.VersionSuffix, + ), Category: gp.Category, Uri: make([]string, 0), } diff --git a/pkg/package/version.go b/pkg/package/version.go index a3e98d39..3dc98e13 100644 --- a/pkg/package/version.go +++ b/pkg/package/version.go @@ -55,6 +55,77 @@ const ( PkgCondMatchVersion = 8 ) +func PkgSelectorConditionFromInt(c int) (ans PkgSelectorCondition) { + if c == PkgCondGreater { + ans = PkgCondGreater + } else if c == PkgCondGreaterEqual { + ans = PkgCondGreaterEqual + } else if c == PkgCondLess { + ans = PkgCondLess + } else if c == PkgCondLessEqual { + ans = PkgCondLessEqual + } else if c == PkgCondNot { + ans = PkgCondNot + } else if c == PkgCondAnyRevision { + ans = PkgCondAnyRevision + } else if c == PkgCondMatchVersion { + ans = PkgCondMatchVersion + } else { + ans = PkgCondInvalid + } + return +} + +func (p PkgSelectorCondition) String() (ans string) { + if p == PkgCondInvalid { + ans = "" + } else if p == PkgCondGreater { + ans = ">" + } else if p == PkgCondGreaterEqual { + ans = ">=" + } else if p == PkgCondLess { + ans = "<" + } else if p == PkgCondLessEqual { + ans = "<=" + } else if p == PkgCondEqual { + // To permit correct matching on database + // we currently use directly package version without = + ans = "" + } else if p == PkgCondNot { + ans = "!" + } else if p == PkgCondAnyRevision { + ans = "~" + } else if p == PkgCondMatchVersion { + ans = "=*" + } + return +} + +func (p PkgSelectorCondition) Int() (ans int) { + if p == PkgCondInvalid { + ans = PkgCondInvalid + } else if p == PkgCondGreater { + ans = PkgCondGreater + } else if p == PkgCondGreaterEqual { + ans = PkgCondGreaterEqual + } else if p == PkgCondLess { + ans = PkgCondLess + } else if p == PkgCondLessEqual { + ans = PkgCondLessEqual + } else if p == PkgCondEqual { + // To permit correct matching on database + // we currently use directly package version without = + ans = PkgCondEqual + } else if p == PkgCondNot { + ans = PkgCondNot + } else if p == PkgCondAnyRevision { + ans = PkgCondAnyRevision + } else if p == PkgCondMatchVersion { + ans = PkgCondMatchVersion + } + return +} + func ParseVersion(v string) (PkgVersionSelector, error) { var ans PkgVersionSelector = PkgVersionSelector{ Version: "", diff --git a/pkg/package/version_test.go b/pkg/package/version_test.go index 60288779..36feb839 100644 --- a/pkg/package/version_test.go +++ b/pkg/package/version_test.go @@ -17,6 +17,8 @@ package pkg_test import ( + gentoo "github.com/Sabayon/pkgs-checker/pkg/gentoo" + . "github.com/mudler/luet/pkg/package" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -181,4 +183,15 @@ var _ = Describe("Versions", func() { Expect(match).Should(Equal(true)) }) }) + + Context("Condition Converter 1", func() { + gp, err := gentoo.ParsePackageStr("=layer/build-1.0") + var cond gentoo.PackageCond = gentoo.PkgCondEqual + It("Converter1", func() { + Expect(err).Should(BeNil()) + Expect((*gp).Condition).Should(Equal(cond)) + Expect(PkgSelectorConditionFromInt((*gp).Condition.Int()).String()).Should(Equal("")) + }) + }) + })