aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/go-version/constraint.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/go-version/constraint.go')
-rw-r--r--vendor/github.com/hashicorp/go-version/constraint.go34
1 files changed, 30 insertions, 4 deletions
diff --git a/vendor/github.com/hashicorp/go-version/constraint.go b/vendor/github.com/hashicorp/go-version/constraint.go
index 8c73df0..d055759 100644
--- a/vendor/github.com/hashicorp/go-version/constraint.go
+++ b/vendor/github.com/hashicorp/go-version/constraint.go
@@ -2,6 +2,7 @@ package version
2 2
3import ( 3import (
4 "fmt" 4 "fmt"
5 "reflect"
5 "regexp" 6 "regexp"
6 "strings" 7 "strings"
7) 8)
@@ -113,6 +114,26 @@ func parseSingle(v string) (*Constraint, error) {
113 }, nil 114 }, nil
114} 115}
115 116
117func prereleaseCheck(v, c *Version) bool {
118 switch vPre, cPre := v.Prerelease() != "", c.Prerelease() != ""; {
119 case cPre && vPre:
120 // A constraint with a pre-release can only match a pre-release version
121 // with the same base segments.
122 return reflect.DeepEqual(c.Segments64(), v.Segments64())
123
124 case !cPre && vPre:
125 // A constraint without a pre-release can only match a version without a
126 // pre-release.
127 return false
128
129 case cPre && !vPre:
130 // OK, except with the pessimistic operator
131 case !cPre && !vPre:
132 // OK
133 }
134 return true
135}
136
116//------------------------------------------------------------------- 137//-------------------------------------------------------------------
117// Constraint functions 138// Constraint functions
118//------------------------------------------------------------------- 139//-------------------------------------------------------------------
@@ -126,22 +147,27 @@ func constraintNotEqual(v, c *Version) bool {
126} 147}
127 148
128func constraintGreaterThan(v, c *Version) bool { 149func constraintGreaterThan(v, c *Version) bool {
129 return v.Compare(c) == 1 150 return prereleaseCheck(v, c) && v.Compare(c) == 1
130} 151}
131 152
132func constraintLessThan(v, c *Version) bool { 153func constraintLessThan(v, c *Version) bool {
133 return v.Compare(c) == -1 154 return prereleaseCheck(v, c) && v.Compare(c) == -1
134} 155}
135 156
136func constraintGreaterThanEqual(v, c *Version) bool { 157func constraintGreaterThanEqual(v, c *Version) bool {
137 return v.Compare(c) >= 0 158 return prereleaseCheck(v, c) && v.Compare(c) >= 0
138} 159}
139 160
140func constraintLessThanEqual(v, c *Version) bool { 161func constraintLessThanEqual(v, c *Version) bool {
141 return v.Compare(c) <= 0 162 return prereleaseCheck(v, c) && v.Compare(c) <= 0
142} 163}
143 164
144func constraintPessimistic(v, c *Version) bool { 165func constraintPessimistic(v, c *Version) bool {
166 // Using a pessimistic constraint with a pre-release, restricts versions to pre-releases
167 if !prereleaseCheck(v, c) || (c.Prerelease() != "" && v.Prerelease() == "") {
168 return false
169 }
170
145 // If the version being checked is naturally less than the constraint, then there 171 // If the version being checked is naturally less than the constraint, then there
146 // is no way for the version to be valid against the constraint 172 // is no way for the version to be valid against the constraint
147 if v.LessThan(c) { 173 if v.LessThan(c) {