aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/opkg/opkg/0009-pkg_depends-fix-version-constraints.patch
blob: f7aa4eac91de1617761e6253a4ba08f735d267a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
From b93ce2249751e0d90dab38e91691a6e9f33c3512 Mon Sep 17 00:00:00 2001
From: Martin Jansa <Martin.Jansa@gmail.com>
Date: Sat, 29 Sep 2012 11:38:03 +0200
Subject: [PATCH 09/10] pkg_depends: fix version constraints

* factor parsing version constraint to str_to_constraint and use that
  from pkg (pkg_version_satisfied) and also pkg_depends (parseDepends)
* fix constraint_to_str(), for EARLIER and LATER it was using '<' and
  '>' which is parsed later as EARLIER_EQUAL and LATER_EQUAL
* show notice when deprecated '<' or '>' is used

Upstream-Status: Submitted
http://code.google.com/p/opkg/issues/detail?id=94

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 libopkg/pkg.c         | 36 +++++++++++--------------
 libopkg/pkg_depends.c | 73 +++++++++++++++++++++++++++++----------------------
 libopkg/pkg_depends.h |  1 +
 3 files changed, 59 insertions(+), 51 deletions(-)

diff --git a/libopkg/pkg.c b/libopkg/pkg.c
index 255c673..1e98b9c 100644
--- a/libopkg/pkg.c
+++ b/libopkg/pkg.c
@@ -968,28 +968,24 @@ pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
      int r;
 
      r = pkg_compare_versions(it, ref);
+     char *op2 = op;
+     enum version_constraint constraint = str_to_constraint(&op2);
 
-     if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
-	  return r <= 0;
-     }
-
-     if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
-	  return r >= 0;
-     }
-
-     if (strcmp(op, "<<") == 0) {
-	  return r < 0;
-     }
-
-     if (strcmp(op, ">>") == 0) {
-	  return r > 0;
-     }
-
-     if (strcmp(op, "=") == 0) {
-	  return r == 0;
+     switch (constraint) 
+     {
+     case EARLIER_EQUAL:
+          return r <= 0;
+     case LATER_EQUAL:
+          return r >= 0;
+     case EARLIER:
+          return r < 0;
+     case LATER:
+          return r > 0;
+     case EQUAL:
+          return r == 0;
+     case NONE:
+          opkg_msg(ERROR, "Unknown operator: %s.\n", op);
      }
-
-     opkg_msg(ERROR, "Unknown operator: %s.\n", op);
      return 0;
 }
 
diff --git a/libopkg/pkg_depends.c b/libopkg/pkg_depends.c
index a72eed7..3dd8240 100644
--- a/libopkg/pkg_depends.c
+++ b/libopkg/pkg_depends.c
@@ -781,7 +781,7 @@ constraint_to_str(enum version_constraint c)
 	case NONE:
 		return "";
 	case EARLIER:
-		return "< ";
+		return "<< ";
 	case EARLIER_EQUAL:
 	       return "<= ";
 	case EQUAL:
@@ -789,12 +789,51 @@ constraint_to_str(enum version_constraint c)
 	case LATER_EQUAL:
 	      return ">= ";
 	case LATER:
-	     return "> ";
+	     return ">> ";
 	}
 
 	return "";
 }
 
+enum version_constraint
+str_to_constraint(char **str)
+{
+	if(!strncmp(*str, "<<", 2)){
+		*str += 2;
+		return EARLIER;
+	}
+	else if(!strncmp(*str, "<=", 2)){
+		*str += 2;
+		return EARLIER_EQUAL;
+	}
+	else if(!strncmp(*str, ">=", 2)){
+		*str += 2;
+		return LATER_EQUAL;
+	}
+	else if(!strncmp(*str, ">>", 2)){
+		*str += 2;
+		return LATER;
+	}
+	else if(!strncmp(*str, "=", 1)){
+		*str += 1;
+		return EQUAL;
+	}
+	/* should these be here to support deprecated designations; dpkg does */
+	else if(!strncmp(*str, "<", 1)){
+		*str += 1;
+		opkg_msg(NOTICE, "Deprecated version constraint '<' was used with the same meaning as '<='. Use '<<' for EARLIER constraint.\n");
+		return EARLIER_EQUAL;
+	}
+	else if(!strncmp(*str, ">", 1)){
+		*str += 1;
+		opkg_msg(NOTICE, "Deprecated version constraint '>' was used with the same meaning as '>='. Use '>>' for LATER constraint.\n");
+		return LATER_EQUAL;
+	}
+	else {
+		return NONE;
+	}
+}
+
 /*
  * Returns a printable string for pkg's dependency at the specified idx. The
  * resultant string must be passed to free() by the caller.
@@ -949,35 +988,7 @@ static int parseDepends(compound_depend_t *compound_depend,
 	  /* extract constraint and version */
 	  if(*src == '('){
 	       src++;
-	       if(!strncmp(src, "<<", 2)){
-		    possibilities[i]->constraint = EARLIER;
-		    src += 2;
-	       }
-	       else if(!strncmp(src, "<=", 2)){
-		    possibilities[i]->constraint = EARLIER_EQUAL;
-		    src += 2;
-	       }
-	       else if(!strncmp(src, ">=", 2)){
-		    possibilities[i]->constraint = LATER_EQUAL;
-		    src += 2;
-	       }
-	       else if(!strncmp(src, ">>", 2)){
-		    possibilities[i]->constraint = LATER;
-		    src += 2;
-	       }
-	       else if(!strncmp(src, "=", 1)){
-		    possibilities[i]->constraint = EQUAL;
-		    src++;
-	       }
-	       /* should these be here to support deprecated designations; dpkg does */
-	       else if(!strncmp(src, "<", 1)){
-		    possibilities[i]->constraint = EARLIER_EQUAL;
-		    src++;
-	       }
-	       else if(!strncmp(src, ">", 1)){
-		    possibilities[i]->constraint = LATER_EQUAL;
-		    src++;
-	       }
+	       possibilities[i]->constraint = str_to_constraint(&src);
 
 	       /* now we have any constraint, pass space to version string */
 	       while(isspace(*src)) src++;
diff --git a/libopkg/pkg_depends.h b/libopkg/pkg_depends.h
index ca0801f..685a722 100644
--- a/libopkg/pkg_depends.h
+++ b/libopkg/pkg_depends.h
@@ -87,6 +87,7 @@ pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
 int pkg_dependence_satisfiable(depend_t *depend);
 int pkg_dependence_satisfied(depend_t *depend);
 const char* constraint_to_str(enum version_constraint c);
+enum version_constraint str_to_constraint(char **str);
 int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
 
 #endif
-- 
1.7.12