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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
/**
* \file lib/problems.c
*/
#include "system.h"
#include <rpmlib.h>
#include "depends.h"
#include "misc.h"
#include "debug.h"
/*@access Header@*/
/*@access rpmProblemSet@*/
/*@access rpmProblem@*/
/*@access rpmDependencyConflict@*/
/*@access availablePackage@*/
rpmProblemSet rpmProblemSetCreate(void)
{
rpmProblemSet probs;
probs = xcalloc(1, sizeof(*probs)); /* XXX memory leak */
probs->numProblems = probs->numProblemsAlloced = 0;
probs->probs = NULL;
return probs;
}
void rpmProblemSetFree(rpmProblemSet tsprobs)
{
int i;
for (i = 0; i < tsprobs->numProblems; i++) {
rpmProblem p = tsprobs->probs + i;
p->h = headerFree(p->h);
p->pkgNEVR = _free(p->pkgNEVR);
p->altNEVR = _free(p->altNEVR);
p->str1 = _free(p->str1);
}
tsprobs = _free(tsprobs);
}
void rpmProblemSetAppend(rpmProblemSet tsprobs, rpmProblemType type,
const availablePackage alp,
const char * dn, const char * bn,
Header altH, unsigned long ulong1)
{
rpmProblem p;
char *t;
if (tsprobs->numProblems == tsprobs->numProblemsAlloced) {
if (tsprobs->numProblemsAlloced)
tsprobs->numProblemsAlloced *= 2;
else
tsprobs->numProblemsAlloced = 2;
tsprobs->probs = xrealloc(tsprobs->probs,
tsprobs->numProblemsAlloced * sizeof(*tsprobs->probs));
}
p = tsprobs->probs + tsprobs->numProblems;
tsprobs->numProblems++;
memset(p, 0, sizeof(*p));
p->type = type;
/*@-assignexpose@*/
p->key = alp->key;
/*@=assignexpose@*/
p->ulong1 = ulong1;
p->ignoreProblem = 0;
p->str1 = NULL;
p->h = NULL;
p->pkgNEVR = NULL;
p->altNEVR = NULL;
if (dn != NULL || bn != NULL) {
t = xcalloc(1, (dn != NULL ? strlen(dn) : 0) +
(bn != NULL ? strlen(bn) : 0) + 1);
p->str1 = t;
if (dn != NULL) t = stpcpy(t, dn);
if (bn != NULL) t = stpcpy(t, bn);
}
if (alp != NULL) {
p->h = headerLink(alp->h);
t = xcalloc(1, strlen(alp->name) +
strlen(alp->version) +
strlen(alp->release) + sizeof("--"));
p->pkgNEVR = t;
t = stpcpy(t, alp->name);
t = stpcpy(t, "-");
t = stpcpy(t, alp->version);
t = stpcpy(t, "-");
t = stpcpy(t, alp->release);
}
if (altH != NULL) {
const char * n, * v, * r;
(void) headerNVR(altH, &n, &v, &r);
t = xcalloc(1, strlen(n) + strlen(v) + strlen(r) + sizeof("--"));
p->altNEVR = t;
t = stpcpy(t, n);
t = stpcpy(t, "-");
t = stpcpy(t, v);
t = stpcpy(t, "-");
t = stpcpy(t, r);
}
}
#define XSTRCMP(a, b) ((!(a) && !(b)) || ((a) && (b) && !strcmp((a), (b))))
int rpmProblemSetTrim(rpmProblemSet tsprobs, rpmProblemSet filter)
{
rpmProblem t;
rpmProblem f;
int gotProblems = 0;
if (tsprobs == NULL || tsprobs->numProblems == 0)
return 0;
if (filter == NULL)
return (tsprobs->numProblems == 0 ? 0 : 1);
t = tsprobs->probs;
f = filter->probs;
/*@-branchstate@*/
while ((f - filter->probs) < filter->numProblems) {
if (!f->ignoreProblem) {
f++;
continue;
}
while ((t - tsprobs->probs) < tsprobs->numProblems) {
/*@-nullpass@*/ /* LCL: looks good to me */
if (f->h == t->h && f->type == t->type && t->key == f->key &&
XSTRCMP(f->str1, t->str1))
/*@innerbreak@*/ break;
/*@=nullpass@*/
t++;
gotProblems = 1;
}
/* XXX This can't happen, but let's be sane in case it does. */
if ((t - tsprobs->probs) == tsprobs->numProblems)
break;
t->ignoreProblem = f->ignoreProblem;
t++, f++;
}
/*@=branchstate@*/
if ((t - tsprobs->probs) < tsprobs->numProblems)
gotProblems = 1;
return gotProblems;
}
/* XXX FIXME: merge into problems */
/* XXX used in verify.c rpmlibprov.c */
void printDepFlags(FILE * fp, const char * version, int flags)
{
if (flags)
fprintf(fp, " ");
if (flags & RPMSENSE_LESS)
fprintf(fp, "<");
if (flags & RPMSENSE_GREATER)
fprintf(fp, ">");
if (flags & RPMSENSE_EQUAL)
fprintf(fp, "=");
if (flags)
fprintf(fp, " %s", version);
}
static int sameProblem(const rpmDependencyConflict ap,
const rpmDependencyConflict bp)
/*@*/
{
if (ap->sense != bp->sense)
return 1;
if (ap->byName && bp->byName && strcmp(ap->byName, bp->byName))
return 1;
if (ap->byVersion && bp->byVersion && strcmp(ap->byVersion, bp->byVersion))
return 1;
if (ap->byRelease && bp->byRelease && strcmp(ap->byRelease, bp->byRelease))
return 1;
if (ap->needsName && bp->needsName && strcmp(ap->needsName, bp->needsName))
return 1;
if (ap->needsVersion && bp->needsVersion && strcmp(ap->needsVersion, bp->needsVersion))
return 1;
if (ap->needsFlags && bp->needsFlags && ap->needsFlags != bp->needsFlags)
return 1;
return 0;
}
/* XXX FIXME: merge into problems */
void printDepProblems(FILE * fp,
const rpmDependencyConflict conflicts, int numConflicts)
{
int i;
for (i = 0; i < numConflicts; i++) {
int j;
/* Filter already displayed problems. */
for (j = 0; j < i; j++) {
if (!sameProblem(conflicts + i, conflicts + j))
/*@innerbreak@*/ break;
}
if (j < i)
continue;
fprintf(fp, "\t%s", conflicts[i].needsName);
if (conflicts[i].needsFlags)
printDepFlags(fp, conflicts[i].needsVersion,
conflicts[i].needsFlags);
if (conflicts[i].sense == RPMDEP_SENSE_REQUIRES)
fprintf(fp, _(" is needed by %s-%s-%s\n"), conflicts[i].byName,
conflicts[i].byVersion, conflicts[i].byRelease);
else
fprintf(fp, _(" conflicts with %s-%s-%s\n"), conflicts[i].byName,
conflicts[i].byVersion, conflicts[i].byRelease);
}
}
#if !defined(HAVE_VSNPRINTF)
/*@-shadow -bufferoverflowhigh @*/
static inline int vsnprintf(/*@out@*/ char * buf, /*@unused@*/ int nb,
const char * fmt, va_list ap)
{
return vsprintf(buf, fmt, ap);
}
/*@=shadow =bufferoverflowhigh @*/
#endif
#if !defined(HAVE_SNPRINTF)
static inline int snprintf(/*@out@*/ char * buf, int nb, const char * fmt, ...)
{
va_list ap;
int rc;
va_start(ap, fmt);
/*@=modunconnomods@*/
rc = vsnprintf(buf, nb, fmt, ap);
/*@=modunconnomods@*/
va_end(ap);
return rc;
}
#endif
const char * rpmProblemString(const rpmProblem prob)
{
/*@observer@*/ const char * pkgNEVR = (prob->pkgNEVR ? prob->pkgNEVR : "");
/*@observer@*/ const char * altNEVR = (prob->altNEVR ? prob->altNEVR : "");
/*@observer@*/ const char * str1 = (prob->str1 ? prob->str1 : "");
int nb = strlen(pkgNEVR) + strlen(str1) + strlen(altNEVR) + 100;
char * buf = xmalloc(nb+1);
int rc;
switch (prob->type) {
case RPMPROB_BADARCH:
rc = snprintf(buf, nb,
_("package %s is for a different architecture"),
pkgNEVR);
break;
case RPMPROB_BADOS:
rc = snprintf(buf, nb,
_("package %s is for a different operating system"),
pkgNEVR);
break;
case RPMPROB_PKG_INSTALLED:
rc = snprintf(buf, nb,
_("package %s is already installed"),
pkgNEVR);
break;
case RPMPROB_BADRELOCATE:
rc = snprintf(buf, nb,
_("path %s in package %s is not relocateable"),
str1, pkgNEVR);
break;
case RPMPROB_NEW_FILE_CONFLICT:
rc = snprintf(buf, nb,
_("file %s conflicts between attempted installs of %s and %s"),
str1, pkgNEVR, altNEVR);
break;
case RPMPROB_FILE_CONFLICT:
rc = snprintf(buf, nb,
_("file %s from install of %s conflicts with file from package %s"),
str1, pkgNEVR, altNEVR);
break;
case RPMPROB_OLDPACKAGE:
rc = snprintf(buf, nb,
_("package %s (which is newer than %s) is already installed"),
altNEVR, pkgNEVR);
break;
case RPMPROB_DISKSPACE:
rc = snprintf(buf, nb,
_("installing package %s needs %ld%cb on the %s filesystem"),
pkgNEVR,
prob->ulong1 > (1024*1024)
? (prob->ulong1 + 1024 * 1024 - 1) / (1024 * 1024)
: (prob->ulong1 + 1023) / 1024,
prob->ulong1 > (1024*1024) ? 'M' : 'K',
str1);
break;
case RPMPROB_DISKNODES:
rc = snprintf(buf, nb,
_("installing package %s needs %ld inodes on the %s filesystem"),
pkgNEVR, (long)prob->ulong1, str1);
break;
case RPMPROB_BADPRETRANS:
rc = snprintf(buf, nb,
_("package %s pre-transaction syscall(s): %s failed: %s"),
pkgNEVR, str1, strerror(prob->ulong1));
break;
case RPMPROB_REQUIRES:
case RPMPROB_CONFLICT:
default:
rc = snprintf(buf, nb,
_("unknown error %d encountered while manipulating package %s"),
prob->type, pkgNEVR);
break;
}
buf[nb] = '\0';
return buf;
}
void rpmProblemPrint(FILE *fp, rpmProblem prob)
{
const char * msg = rpmProblemString(prob);
fprintf(fp, "%s\n", msg);
msg = _free(msg);
}
void rpmProblemSetPrint(FILE *fp, rpmProblemSet tsprobs)
{
int i;
if (tsprobs == NULL)
return;
if (fp == NULL)
fp = stderr;
for (i = 0; i < tsprobs->numProblems; i++) {
rpmProblem myprob = tsprobs->probs + i;
if (!myprob->ignoreProblem)
rpmProblemPrint(fp, myprob);
}
}
|